Thread: What does ++ mean?

  1. #16
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Quote Originally Posted by Dae
    a = ++c; //would be 6
    I'd rather write
    Code:
    a = c++ + 1;
    it makes more sense, and looks awesome
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  2. #17
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by Daved
    Operator precedence doesn't matter in determining whether the value x is set to is the originally pointed to value or the value pointed to after the increment. It only determines whether the pointer is incremented or the value pointed to is incremented. Since ++ has precedence, the pointer is incremented.

    What matters as to what value x gets is whether it is prefix or postfix. In this case it is postfix, so x gets the originally pointed to value, and the pointer is incremeneted afterwards.
    You got me.

  3. #18
    Registered User
    Join Date
    Nov 2005
    Posts
    71
    C++ = similar to C = C + 1 which also the same as C+=
    hope this is helpful

  4. #19
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Quote Originally Posted by gtr_s15
    C++ = similar to C = C + 1 which also the same as C+=
    hope this is helpful
    i have allready spoken that!
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  5. #20
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Daved
    Dae, you shouldn't be using ++ or -- on y in your example anywhere. It's all undefined. It worked in some cases for you because of the way memory is laid out on your current platform.

    Try making an array and then point y at the array. Then you can see a better (and more legal) version of what's going on.
    Oh, yeah. I was just testing in the context of the OP's code (I couldnt tell if it had an array), and didn't expect it to be very legal or good to do, haha. Alright, I'll try that, thanks. Good explanation about the precedence btw.

    Code:
     and just to make this thread even more confusing (*x)++ will incremenet the value pointer to by x rather than x pointer itself.
    Thats not very confusing... maybe if you didn't have the brackets it would.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed