C Programming :: Declarations and Initializations - Discussion
2 / 54
#include<stdio.h>
int main() {
int i,j;
j = 10;
i = j++ - j++;
printf("%d %d", i,j);
return 0;
}
#include<stdio.h>
int main() {
int i,j;
j = 10;
i = j++ - j++;
printf("%d %d", i,j);
return 0;
}
A0 12
B12 12
C0 0
D12 0
Show Explanation
i=10-11 //here j is post incremented twice
j=12
Asked In ::
It also depends on the compiler, if optimization level (O1/O2/O3) is set, it will be 0 12 else it will be -1 12. for that you while compiling the program, compile with different optimization level and you will get a different answer.
But if you declare j as volatile variable, compiler optimization level dont impact.
As here in option 0 and 12 is only mention, not -1 12 then option A will be correct option. i.e 0 12
Read Full Answer
Report Error
Please Login First Click Here
4th line of the program says j=10 . 5th line says j means post increment so after that line is executed j value will become 11 but during the execution of the 5th line j value is still 10 so i= 10-10=0
Now in the 5th line itself there has been two times increment of j so final value will be 12.
Read Full Answer
Report Error
Please Login First Click Here
the ans is -1,12
i=10-11 //here j is post incremented twice
j=12
Read Full Answer
Report Error
Please Login First Click Here
Line 4 says that value of j=10. In line 5, value of i will be calculated as i=10-10=0, but value of j is also post incremented twice which means when the value of j will be printed, it will display 10+1+1=12. So correct answer is A. 0 12
Read Full Answer
Report Error
Please Login First Click Here