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?

Answers were Sorted based on User's Feedback



void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1..

Answer / 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

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1..

Answer / vishnu

first calculations will be done from right to left and then
prints accroding to the parameters passed.

Is This Answer Correct ?    29 Yes 8 No

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1..

Answer / sathish

execution does from right to left and while printing it goes from left to right.

Is This Answer Correct ?    18 Yes 3 No

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1..

Answer / 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

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1..

Answer / hemanth

All,

output of above code is compiler depended i.e the order of
evalulation.

Is This Answer Correct ?    8 Yes 5 No

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1..

Answer / keerthi

while printing the output it starts from right hand
side ..so first 'a++' value is printed then '++a' value and
last it prints 'a' value

Is This Answer Correct ?    12 Yes 16 No

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1..

Answer / minchoo

answer is 2 2 1 and not 3 3 1

Is This Answer Correct ?    4 Yes 43 No

Post New Answer

More C Interview Questions

write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values.  The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.

0 Answers  


How to establish connection with oracle database software from c language?

0 Answers  


which operator is known as dummy operator in c?

2 Answers   Wipro,


write a program to convert a expression in polish notation (postfix) to inline (normal)

0 Answers   Siemens,


void main() {int a[5],i,b=16; for(i=0;i<5;i++) a[i]=2*i; f(a,5,b); for(i=0;i<5;i++) printf("\n %d",a[i]); printf("\n %d",b); } f(int *x,int n,int y) { int i; for(i=0;i<n;i++) *(x+i)+=2; y=y+2; }wat r the errors in the prg.and improvise the prg to get o/p.?

2 Answers   TCS,


main() { int a = 65; printf(“%d %o %x”,a,a,a); } Output 65 101 41 Please explain me.How it is coming like that?

3 Answers   Excel,


Define function pointers?

1 Answers  


What does p mean in physics?

0 Answers  


question-how to run a c programme.

6 Answers  


Which of the following about the C comments is incorrect ? a.commentscan go over multiple lines b.comments can start any where in the line c.a line can contain comments with out any language statements d.comments can occur within comments

6 Answers   TCS,


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

0 Answers   IBM,


What does 3 mean in texting?

0 Answers  


Categories