int val = 5;
printf("%d",++val++); //gives compilation error : '++' needs l-value
int *p = &val;
printf("%d",++*p++); //no error
Could someone explain these 2 cases? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
++val++is the same as++(val++). Since the result ofval++is not an lvalue, this is illegal. And as Stephen Canon pointed out, if the result ofval++were an lvalue,++(val++)would be undefined behavior as there is no sequence point between the++s.++*p++is the same as++(*(p++)). Since the result of*(p++)is an lvalue, this is legal.