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....

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain pointers in c programming?

635


What is a pointer and how it is initialized?

609


How can you find the exact size of a data type in c?

601


Array is an lvalue or not?

640


What are the types of assignment statements?

630






To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

2190


What is a substring in c?

588


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

837


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

645


Explain what is the difference between the expression '++a' and 'a++'?

627


Can a pointer be volatile in c?

535


What are unions in c?

582


what are enumerations in C

724


How are 16- and 32-bit numbers stored?

725


Tell me when would you use a pointer to a function?

608