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

if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above

702


What is class and object in c?

578


how many errors in c explain deply

1623


what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?

1892


What is a stream in c programming?

583






#include { printf("Hello"); } how compile time affects when we add additional header file .

1416


What is clrscr ()?

627


What is the purpose of the statement: strcat (S2, S1)?

636


Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon

5458


What are loops c?

606


What is the difference between volatile and const volatile?

556


What are the scope of static variables?

595


What are structure members?

586


c program for searching a student details among 10 student details

1646


What is pointer to pointer in c?

626