program is:
main{
int i=-3, j=2, k=0, m;
++i %26amp;%26amp; ++j || ++k //..........line No. 3
printf("%d %d %d %d", i,j,k,m);
}
Output is : -2 3 0 1
When we change order in the statement at line no. 3 as:
++i || ++j %26amp;%26amp; ++k the output is different.
Q1. why the value of k variable is 0 when we have used increament operator, how this statement works?
Q2. What will be the output if the logical operator's order is changed?
Plz clear my doutbt, for it, i'll be grateful
Regards
Problem is about C program output where after changing the order in statement the output is different. why so?
A1 k is 0 because the expression got short circuited. Since i and j are non zero values, the value of the || will always be true, so the right side does not need to be evaluated and k is never incremented.
A2 when you switched to put the || first, no short circuiting can occur (since i and j are non zero, k still needs to be evaluated because of the %26amp;%26amp;). The value of m is non-determinate in both cases.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment