Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

void main()
{
int a=1;
printf("%d %d %d",a,++a,a++);
}
the output is supposed to be 1 2 2....but it is 3 3 1
this is due to calling conventions of C. if anyone can
explain me how it happens?

Answer Posted / sumant

In C the parameters are pushed on the stack from right to
left. So
1> it will push a=1 on the stack and do a++ making a=2
2> it will porform ++a making a = 3 and push value 3
3> it will push a on the stack which is 3

so the stack will have values 1 3 3 and it will POP in
the reverse order and thus printf will display 3 3 1

Is This Answer Correct ?    52 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of operators in c?

1102


difference between native and cross compilers

2171


Which control loop is recommended if you have to execute set of statements for fixed number of times?

1409


What is size of union in c?

1080


Why is %d used in c?

1059


Is null always defined as 0(zero)?

1177


When can a far pointer be used?

1077


What does static variable mean in c?

1142


What are the types of assignment statements?

1111


What is a macro, and explain how do you use it?

1124


What is pivot in c?

1077


Is it possible to use curly brackets ({}) to enclose single line code in c program?

1373


Is there a way to switch on strings?

1128


Explain 'bus error'?

1164


Which programming language is best for getting job 2020?

1099