Possible duplicate:
What is the correct answer for cout <c ++ <c ;?
I just dropped the text when I suddenly noticed.
#include <iostream> int main() { int array[] = {1,2,3,4}; int *p = array; std::cout << *p << "___" << *(p++) << "\n"; // output is 1__1. Strange, but I used brackets! it should be at // first incremented, not clear. p = array; std::cout << *p << "___" << *(++p) << "\n"; // output is 2_2 fine, why first number was affected? I didn't intend // to increment it, but it was incremented p=array; std::cout << *p << "___" << *(p + 1) << "\n"; // output is 1_2 - as it was expected p = array; return 0; }
Such behavior is strange to me, why is this so?
source share