Sunday, July 12, 2009

Please help! I'm having a problem grasping the math concept in C++ programming.?

I get that k++ is the same as k=k+1, but what does ++k =, and what does - - k =, or k - - =. This should be easy, I'm sure, but I just can't wrap my brain around it. Any help would be great as I have a test in this class on Monday. Thanks so much!

Please help! I'm having a problem grasping the math concept in C++ programming.?
Well, suppose theres the line





a=k++;





in your code. When this line is run, the value of a will be equal to k, and AFTER that, the value of k will be incremented(increased by 1)


And if the code is like:





a=++k;





then the value of k will be increased FIRST then it will be assigned to a.





When ++ or -- is before a variable, the value changes before the execution of the code, and when its after the variable, the value is changed after execution.
Reply:++k is pre incrementation and k++ is post incrementation. i.e. e.g. a value will be incremented in the former before k and the later is the opposite.

sp

No comments:

Post a Comment