Hi sir,
When i executed the below code
#include<stdio.h>
int main()
{
int a = 10;
float b= 10.5;
int c = 20;
printf(“++a = %d\n”, ++a);
printf(“a++ = %d\n”, a++);
printf(“++b = %f\n”, ++b);
printf(“y = %d\n”, ++a + a++);
return 0;
}
The Output of y was 27, can i know how the Increment and Decrement operator works when it is assigned to an expression?
Regards.
[ EXTREMELY SORRY FOR THE LONG DELAY. I HAD BEEN OUT OF CONTACT. ….. MLS Shastry ]
Please note that if you use ++ / — operator on the same symbol multiple times in the same statement, the result is not defined by the C Language Definition. The result depends upon the sequence of instructions generated by the particular C Compiler. It may vary among the different compilers / systems. Hence the best approach is :
NEVER USE ++ / — ON THE SAME SYMBOLIC REFERENCE MORE THAN ONCE IN THE SAME STATEMENT.
The actual result depends on what are known as Event Points during compilation — the points of time when compiler ejects machine code into the output object stream.
ONE EXCEPTION : If the operators are used in the parameters passed to a procedure, the result is uniform across C Compilers since C Language Definition decrees that the parameter values must be evaluated and pushed onto the stack exactly in the reverse order of their appearance.
Please login first to submit.