+ 1
What is the output and why?
#include <stdio.h> void main() { Â Â Â Â int x = 97; Â Â Â Â int y = sizeof(x++); Â Â Â Â printf("x is %d", x); }
3 Answers
+ 2
output is x is 97
Because
output value of x after increment is still 97 as compared to the expected value which is 98
because of sizeof operator don't need to evaluate the expression in side it,it only gives sizeof the data type
So x value is remain same
+ 1
The C compiler evaluates the sizeof operand during compile time and just replaces the term with the appropriate constant. So there is no code at run time that executes the post increment.
I have read that run-time evaluation of sizeof is a relatively new feature that was added to support variable length arrays (VLAs). However, I would suppose that the new standard did not update run-time evaluation of arbitrary expressions in order to maintain compatibility for programs written under past standards.