I'm a bit confused as to the interpretation of the following snippet:
*somepointer++ = somevalue
Does it increment the pointer and then assigns the value to what it points to, or does it assign the value to what it points to and then increments it?
None.
somevalue will get the value of somepointer + 1.
None.
I just tested it (it took 5 minutes). The compiler outputs an error because, quote "Test.cpp:7: error: invalid lvalue in assignment". Here's the code snippet I tested:
#include<iostream>
int main()
{
int x = 0;
x++ = 2;
std::cout << x << std::endl;
}
None.
x should be a pointer to another variable, not just a variable, else it doesn't make sense (and doesn't work, from your experiences).
And Falkoner, what on earth are you trying to say? If it means what I think it means, it's horribly wrong (the right hand side of the expression gets something assigned to????), and if not, well you should change your wording. And if it was sarcasm or a joke, well it's not a funny one.
None.
Falkoner and Laser Dude are retards who don't know what the fuck they are talking about.
void main()
{
int value = 10;
int *pointer = &value;
cout << (*pointer);
*pointer++ = 4;
cout << (*pointer);
}
As far as I can tell the address in memory the pointer is aimed at is what is being increased by the ++. Which is exactly what should happen, check out this priority table:
http://paowang.com/blog/hufey/archives/010535.htmlSo its basically a horrible memory leak, you're altering some address in memory you don't know jack about.
None.
So it's assignment first, increment after. Thanks.
The code is actually looping through known memory in compression/decompression stuff I'm porting from C++ to VB.Net as part of the cross-os MPQ library I'm working on, so it's not some random memory.
None.
If ++ (or --) is after the variable name, it always takes effect after the statement executes. So if you use variablename++ in an expression, the value used in the expression is the value before the increment. If you have ++ (or --) before the variable name, then it does the operation before reading the value of the variable. For example:
x = 3;
y = 2 + x++;
After those two statements, x = 4 and y = 5 because x was incremented after the second statement finished. This is how the post-increment operator works (variable++). An example of the pre-increment operator (++variable):
x = 3;
y = 2 + ++x;
Same as before, x = 4 after the second statement, but this time y = 6 because x was incremented before the calculation.
None.
Anyone who doesn't know what a pointer is should
not be posting in this. Esponeo is right anyway.
None.
Oh, there was one more thing I did forget to mention.
When using ++ (or --) with dereferenced pointers, it applies it to the pointer, not the memory location, unless you put the *variablename in parentheses and the ++ (or --) outside. For example,
*pointername++ increments pointername after the statement that used it; it does not increment *pointername. To increment *pointername this way, you must use (*pointername)++.
Yes, it can be kind of confusing, but that's just the way it is.
Post has been edited 1 time(s), last time on Jan 18 2008, 2:13 am by ShadowFlare.
None.