main()
{ int i=5;
printf("%d",++i + i);

} output is 10

------------------------
main()
{ int i=5;
printf("%d",i++ + i);

}output is 12
why it is so? give appropiate reason....

Answers were Sorted based on User's Feedback



main() { int i=5; printf("%d",++i + i); } output is 10 --------------------..

Answer / sudarsan.tuku@gmail.com

1>On the 1st que the ans. is 12
bcz perform the pre increment 1st then add them.
After the pre increment the value of i becomes 6 and
then it perform the add operation i.e. i+i=6+6=12.

2>output is 10
It 1st perform the pre operation but there is no pre
operation in the que.
2ndly it perform the operation i.e i+i=5+5=10.
3rdly it perform post operation i.e i++ so i becomes 6.
but here the output is 10.

Is This Answer Correct ?    16 Yes 2 No

main() { int i=5; printf("%d",++i + i); } output is 10 --------------------..

Answer / ashi smita

in first program i is post increment than i=5 and i=5+5=10
than i is increment by 1 and the value of i is 6 but second
program first i is preincrement by 1 and the value of is 6
than sum of i is 12.

Is This Answer Correct ?    3 Yes 10 No

Post New Answer

More C Interview Questions

52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?

9 Answers  


what's the return value of malloc()

9 Answers  


How pointers are declared?

0 Answers  


which of 'arrays' or 'pointers' are faster?

5 Answers  


what is the difference between structural,object based,object orientd programming languages?

1 Answers   PanTerra,






how i m write c program 1.check prime number 2.prime number series

1 Answers  


main difference between c and c++ language

1 Answers  


what is the meaning of 'c' language

3 Answers  


write a c prog for removing duplicate character from an array and sorting remaining elements using a single array

1 Answers  


Is it better to use malloc() or calloc()?

0 Answers   Aspire, Infogain,


Is the below things valid & where it will be stored in memory layout ? static const volatile int i; register struct { } ; static register;

2 Answers   Lucent,


main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(“%d”,x); }

8 Answers   Vector,


Categories