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

How can I change the size of the dynamically allocated array?

0 Answers  


write a program to find the sum of the array elements in c language?

24 Answers   ICT, Infosys, Wipro,


Define VARIABLE?

0 Answers   ADP,


Why c is known as a mother language?

0 Answers  


what is array?

8 Answers  






What is the usage of the pointer in c?

0 Answers  


write a program to display the array elements in reverse order in c language

16 Answers  


Which header file is essential for using strcmp function?

0 Answers  


two variables are added answer is stored on not for third variable how it is possible?

3 Answers  


How can I pad a string to a known length?

0 Answers  


How can I direct output to the printer?

0 Answers  


what is stack , heap ,code segment,and data segment

0 Answers  


Categories