Tuesday, 27 August 2013

output of prefix postfix expressions in C/C++

output of prefix postfix expressions in C/C++

Following is an example code:
#include<stdio.h>
void main(){
int i=0;
printf("%d,%d,%d", i++, i, ++i);
return 0;
}
Are questions like these compiler dependent or they have undefined
behavior? I am not able to devise a proper procedure for solving such
questions, it works for some but I get incorrect output for others.
More examples:
printf("%d,%d,%d", ++i, ++i, i++);
printf("%d,%d,%d", i, ++i, i++);
Is there a certain rule which GCC uses to solve such questions? Or this
has undefined behavior?

No comments:

Post a Comment