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 / pranjal kumbang

Output:3 3 1 This
is because,C's calling convention is from right to left.That
is ,firstly 1 is passed through the expression a++ and then
a is incremented to 2.Then result of ++a is passed.That is,a
is incremented to 3 and then passed.Finally,latest value of
a,i.e. 3,is passed.Thus in right to left order,1 ,3, 3 get
passed.Once printf() collects them,it prints them in the
order in which we have asked it to get them printed(and not
the order in which they were passes).thus 3 3 1 gets
printed.

Is This Answer Correct ?    8 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between exit() and _exit() function in c?

1075


Write a program to know whether the input number is an armstrong number.

1116


What are data types in c language?

1056


An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode

1084


Can one function call another?

1112


program to find out date after adding 31 days to a date in the month of febraury also consider the leap year

3088


What is the translation phases used in c language?

1124


How reliable are floating-point comparisons?

1094


Write a program to show the change in position of a cursor using c

1058


What are the different types of C instructions?

1309


How important is structure in life?

1082


Do string constants represent numerical values?

1392


What are register variables? What are the advantage of using register variables?

1187


write a program to find out prime number using sieve case?

2095


A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM

2121