sunny said:
Hi All
does the output of this command depend on the compiler.
int val=1234;
int* ptr=&val;
printf("%d %d %d",val,*ptr++,++*ptr);
O/p
i was expecting 1234,1234,1235.
but i got 1235, 1235, 1235
Aha, your expectation seems to be along the lines of "since we read
from left to right, function parameters must be evaluated likewise."
Actually, many C implementations are bousphredonic, like Hebrew and
Arabic. A picture of Kernigan and Richie may be enlightening in this
regard.
The convention varies from language to language and in C, even among
implementations. Really weird languages like Algol 60 actually pass
the code to evaluate each parameter, which can lead to extremely
bizarre results. for example you can pass:
PleaseDo( A, 100, x, y, x * y )... and Algol will cheerfully evaluate x
* y for x, y, 1 to 100 and stuff the results in A[x,y]. i.e. you can
pass EXPRESSIONS that are evaluated in the time and place of the called
function!
But I digress.