You are here:

C/c program

Advertisement


Question
hello sir,
          please give me the explanation about the output of the following program...
 
main()
{
 int i=5;

 printf("%d",i++ + ++i);
}

output: can't predicted exactly.         

          thank you
           seema.

Answer
You have i++ + ++i.
So, the expression has to be processed before sending to printf().
When i++ is processed, it's value is 5 and hence 5 will be taken.
Now, when it goes to ++i, the value of i is 6 (because of i++ that was done before).
Since ++i is a post increment, 6 will be incremented to 7.
So, i++ + ++i becomes 5 + 7 and it's value is 12.
So, 12 will be the o/p.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.