+ 1
Value is not incrementing
In the following code the values of i is not incrementing. I am unable to understand such kind of behavior. #include <iostream> using namespace std; int main() { int i=5,*j; j=&i; *j++; cout<<i<<" "<<j<<endl; ++*j; cout<<i<<" "<<j<<endl; return 0; }
3 Réponses
+ 4
It’s because of operators precedence, see the table here:
http://en.cppreference.com/w/cpp/language/operator_precedence
++ has a higher precedence than dereferencing *
0
I understand ,but the second "++*j" is preincrement and should increment value of "i".so the final value of i should be 7 .