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
What is an array? What the different types of arrays in c?
What are logical errors and how does it differ from syntax errors?
What is the difference between class and object in c?
Explain how can I manipulate strings of multibyte characters?
stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.
‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .
What are the advantages and disadvantages of a heap?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
What is %lu in c?
What is memcpy() function?
Explain the use of 'auto' keyword in c programming?
Why structure is used in c?
Tell me about low level programming languages.
Does c have circular shift operators?
When should volatile modifier be used?