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 structure padding and packing in c?

627


Explain how do you sort filenames in a directory?

616


find the sum of two matrices and WAP for it.

642


write a progrmm in c language take user interface generate table using for loop?

1576


Write a program to identify if a given binary tree is balanced or not.

691






Is it fine to write void main () or main () in c?

550


Apart from dennis ritchie who the other person who contributed in design of c language.

817


Wt are the Buses in C Language

2755


Explain how can I manipulate strings of multibyte characters?

788


What is the difference between char array and char pointer?

531


What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file

673


What are the types of type specifiers?

625


What is structure of c program?

609


What is c basic?

606


What is s or c?

604