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

explain what is an endless loop?

1052


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1921


hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..

1879


What are the storage classes in C?

1122


What the different types of arrays in c?

1033


explain how do you use macro?

1115


What is extern variable in c with example?

972


How can I invoke another program or command and trap its output?

1065


What is ponter?

1234


What are structures and unions? State differencves between them.

1119


What is the scope of global variable in c?

966


How do you construct an increment statement or decrement statement in C?

1189


What is the purpose of ftell?

1049


Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?

971


What are the different types of errors?

1089