GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 381 of 453    Print  
What will be the output of the code?

#include
main()
{
int a=10;
int b;
b=a++ + 20;
printf("a= %d b= %d", a, b);
}
The o/p will be 11 30. Can somebody tell me how?


  
Total Answers and Comments: 3 Last Update: July 02, 2008     Asked by: vrijesh28 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Dan Dancescu
 
The output is 11 30, because "++" is a postfix operator (applied after the operation) so the value that gets assigned to b is the initial value of a, which is 10, plus 20.

So b will be 30. Then a is incremented by 1, so a becomes 11.

Therefore this program prints out 11 30

Above answer was rated as good by the following members:
rajani_vaddepalli15
October 09, 2007 22:45:26   #1  
Dan Dancescu        

RE: What will be the output of the code?#i...
The output is 11 30 because "++" is a postfix operator (applied after the operation) so the value that gets assigned to b is the initial value of a which is 10 plus 20.

So b will be 30. Then a is incremented by 1 so a becomes 11.

Therefore this program prints out 11 30

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
November 07, 2007 01:17:25   #2  
amma_mans80 Member Since: November 2007   Contribution: 1    

RE: What will be the output of the code?#i...
a 11 b 30
 
Is this answer useful? Yes | No
July 02, 2008 04:51:22   #3  
jintojos Member Since: May 2008   Contribution: 29    

RE: What will be the output of the code?#includemain(){int a=10;int b;b=a++ + 20;printf("a= %d b= %d", a, b);}
The variable a is incremented by one only after completing
the statement b a++ + 20;
So after executing the statement b a++ + 20 the variable b will have the value 30.
Then the value of variable a is incremented that is why the out put is 11 30.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape