C
Programming and Technical
undefined
main()
{
int i=5,j;
j = i++ + ++i + ++i + ++i;
printf("%d",j);
}
Read Solution (Total 34)
-
- j=5+7+8+9
hence j= 29 - 9 years agoHelpfull: Yes(18) No(3)
- j = i++ + ++i + ++i + ++i;
i++ will increment the value of i, but return the original value that i held before being incremented.
++i will increment the value of i, and then return the incremented value.
j = 5+7+8+9
j =29 - 9 years agoHelpfull: Yes(7) No(1)
- j = i++ + ++i + ++i + ++i;
let post increment keep aside, then expression becomes
j = i + ++i + ++i + ++i;
then evaluate the expression consider the priorities
i.e i-> 5 -> 6-> 7-> 8
substituting the value in the final expression after implementing the all pre-increment operator i.e Right TO Left.
finally i becomes 8, then substitute the value in the remaining expression
j = 8 + 8 + 8 + 8
i.e j=32
the post increment should be consider finally to variable i,
i becomes i++ final value of i is 9.
the output of the program will be
9 32
better to consider memory blocks for variables for easy understanding. - 9 years agoHelpfull: Yes(6) No(0)
- j=6+6+7+8
=27 - 9 years agoHelpfull: Yes(2) No(2)
- It is compiler dependent, so no correct answer can be given,,
- 9 years agoHelpfull: Yes(2) No(0)
- j=i++ + ++i + ++i + ++i
step1:
++i=6
++i=7
++i=8
now i=8;
step 2:
y=i+i+i+i;
y=28;
step 3:
i++=9
i=9 - 9 years agoHelpfull: Yes(2) No(0)
- follows preorder - algebra -postorder
output- 32 - 9 years agoHelpfull: Yes(1) No(1)
- 6+7+8+9=30
- 9 years agoHelpfull: Yes(1) No(1)
- 6+6+7+8=27
- 9 years agoHelpfull: Yes(1) No(1)
- j=5+7+8+9
hence j= 29 - 9 years agoHelpfull: Yes(0) No(0)
- I THINK IT SHOULD BE COMPILLER ERROR BECAUSE I WILL STATRT WORKING FROM LEFT OR RIGHT IT DEPENDS ON COMPILLER
- 9 years agoHelpfull: Yes(0) No(1)
- j= 5+7+8+9=29
- 9 years agoHelpfull: Yes(0) No(2)
- the value in post increment is incremented after semi colon but in pre increment the value increases at the same place ........before semicolon of the second statement value of x is pre incremented 3 times so i=5+1+1+1 ie 8..now the statement means j=8+8+8+8 ie 32 and after semicolon the post incrementation will take place and value will i will become 9.......so output of program will be 32
- 9 years agoHelpfull: Yes(0) No(0)
- output will be 32
- 9 years agoHelpfull: Yes(0) No(1)
- j=5+7+8+9
answer is j=39 - 9 years agoHelpfull: Yes(0) No(0)
- j=5+ 7+ 8 +9 =29
- 9 years agoHelpfull: Yes(0) No(0)
- j = 32
i = 9 - 9 years agoHelpfull: Yes(0) No(1)
- ans is 32.
this is register evaluation,it works with priority i.e.,pre operator has higher priority than post operator.
In register evaluation data need to substituted after modifying all pre values.
j=8+8+8+8=32 (3 pre operator )
- 9 years agoHelpfull: Yes(0) No(0)
- 21...i++ means it will be incremented before the excecution of that statement and ++i means it will be incremented after the excecution of that statement so 6+5+5+5=21
- 9 years agoHelpfull: Yes(0) No(0)
- if copiler is 16 bit the ,,, ans = 16
if compier is 32 bit ,,,,,,, ans = 32 - 9 years agoHelpfull: Yes(0) No(0)
- i=5
++i=7
++i=8
++i=9
ans:5+7+8+9=29 - 9 years agoHelpfull: Yes(0) No(0)
- j=5+7+8+9=29
- 9 years agoHelpfull: Yes(0) No(0)
- Answer must be 27
6+6+7+8=27 - 9 years agoHelpfull: Yes(0) No(0)
- j=29
I dont know the reason - 9 years agoHelpfull: Yes(0) No(0)
- Associatibity of increament operator is become from right to left so according to this rule value of this is 27
- 9 years agoHelpfull: Yes(0) No(0)
- j=5+7+8+9=29
- 9 years agoHelpfull: Yes(0) No(0)
- doesnot space between the incerment and + operator it gives an error bad operand
- 9 years agoHelpfull: Yes(0) No(0)
- u can not pridict the output unless compiler is provided
same code will generate different output on different compilers like dev c,turbo c, and so on - 9 years agoHelpfull: Yes(0) No(0)
- ans is 27
j = 5 + 7 + 8 + 9 - 9 years agoHelpfull: Yes(0) No(0)
- since arithmetic operation are evaluated from left to right, and unary are evaluated from right to left..
j=(((i++ + ++i) + ++i )+ ++i)
j=((( 6 + 6) + ++i)+ ++i) -->i=7
j=((12 + 8)+ ++i) --> i=8
j=20 + 9
j=29 - 9 years agoHelpfull: Yes(0) No(0)
- 5+6+7+8
28 - 9 years agoHelpfull: Yes(0) No(0)
- Undefined symbol J
- 9 years agoHelpfull: Yes(0) No(0)
- It will just like j=5+7+8+9(29)
- 7 years agoHelpfull: Yes(0) No(0)
- Actually, it depends on the compiler
according to one compiler
i is pre-incremented 3 times so i becomes 8 and that 8 will be placed in the place of i so
j=8+8+8+8==>32
according to another compiler
j=5+7+8+9==>29 - 7 years agoHelpfull: Yes(0) No(0)
C Other Question