964 views
3 votes
3 votes
Q)What is the output of the following C program fragment?Assume size of an integer is 4 Bytes

#include<stdio.h>

int main()

{

int i = 5;

int var = sizeof( i++);

printf("%d %d",i ,var);

return 0;

}

 

A) 5 4          B) 6 4          C) 5 8                D)Compiler Error

1 Answer

6 votes
6 votes

int i=5

int var= sizeof(i++);

But sizeof(variable), variable will not be evaluated until it is variable length array type.

so i++ will not be incremented
==>> as sizeof is compile time operator so during compilation value will be generated and hence not evaluted during run time
answer:- 5,4

https://stackoverflow.com/questions/8225776/why-does-sizeofx-not-increment-x

Thanks srestha for corrrection

edited by

Related questions

1 votes
1 votes
1 answer
1
radha gogia asked Jul 10, 2018
1,720 views
If I have an array :int a [3][4] ; How to evaluate below Outputs ? 1. sizeof(*a) 2.sizeof( a) 3. sizeof(a) Please explain precisely .
1 votes
1 votes
1 answer
2
Shiva Sagar Rao asked Feb 16, 2019
674 views
#include <stdio.h int main() { int a = 1; char d[] = "ab"; printf("%d", sizeof(a+d)); return 0; }Explain the Output
1 votes
1 votes
2 answers
3
raushan sah asked May 24, 2018
1,170 views
#include<stdio.h int main() { char *s="\123456789\n"; printf("%d", sizeof(s)); return 0; }why this piece of code gives output $8$please explain. thanx