0

What is the output and why? Ignore syntax i want to know output only

a=3; Printf("%d %d %d ",a,a++,a);

26th Aug 2020, 11:12 AM
Gaurav Rawat
Gaurav Rawat - avatar
7 Answers
+ 3
HBhZ_C I read the qoura post, and looked bit more into it, It seems like, different compilers on different processor behave differently, like it was mentioned the amd based compilers store the parameters in registers but upto certain limit and when limit overflows then the stack is used And regarding the question, whenever we modify one variable more than once without performing any operation, it throws a warning as undefined, or -Wsequence-point , which means operation on a is undefined So the output which we get here is not consistent to compilers, so it's meaningless, we cannot guess the way the output is produced
26th Aug 2020, 4:42 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 2
This will depends oh how the compiler will treat the parameter.They are evaluated from right to left in last in first out stack order.so 4 3 4 will be the output.See Quora.com and the qs : what is the output of a=5 printf("%d %d %d",a++,a++,++a) in c and how?
26th Aug 2020, 12:15 PM
HBhZ_C
HBhZ_C - avatar
+ 2
int a=3; printf("%d %d %d", a, a++, a); // result: 4 3 4 std::cout<< a << a++ << a; // result: 3 3 4
26th Aug 2020, 12:16 PM
electron
electron - avatar
+ 2
HBhZ_C I don't think we can store an expression in a stack, a a++ a is this way are you referring??
26th Aug 2020, 12:23 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 2
No the fonction parameters are stored in the stack during function call.Here it is printf function with a a++ and a again mr Мг. Кнап🌠
26th Aug 2020, 4:36 PM
HBhZ_C
HBhZ_C - avatar
+ 2
Мг. Кнап🌠 Also your question is treated in stackoverflow :where in memory are my variables stored in c?Stockage manner is not the same for each kind of variables types
26th Aug 2020, 4:54 PM
HBhZ_C
HBhZ_C - avatar
+ 1
Parameters are treated differently than the other variables https://stackoverflow.com/questions/16304705/where-are-parameter-variables-stored-in-memory#:~:text=There%20are%20no%20methods%20in,ones%2C%20are%20stored%20in%20the%20.&text=Local%20static%20variables%20are%20stored,immediately%20before%20the%20return%20address.
26th Aug 2020, 4:58 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar