C
Programming and Technical
Programming
Arrays
#include
void main()
{
int a=3,b=6,c=8;
printf("%d %d %d");
getch();
}
the output is
8 6 3
HOW?
Read Solution (Total 9)
-
- printf() statement is always executed from right to left (when no variable is assigned).
So, printf("%d %d %d") will execute from right to left and will give values of c,b & a respectively (the top value of stack to the lower). So, o/p will be 8 6 3
But, when printf("%d %d %d", a,b,c) is written, then the o/p will be 3 6 8 (as the variables are already assigned in the statement). - 8 years agoHelpfull: Yes(7) No(0)
- I got garbage values when I run this code.
- 8 years agoHelpfull: Yes(5) No(0)
- 8 6 3 because in stack top first the value of c stored then b and then a.
- 8 years agoHelpfull: Yes(3) No(0)
- The output of this program is actually unexpected or i can say compiler dependent.
According to C standards the output should be garbage only. - 7 years agoHelpfull: Yes(3) No(0)
- It will show a compile error, because there is no header defined specifically but #include!
- 8 years agoHelpfull: Yes(0) No(0)
- because the printf stmt always read from right to left
so the output is 8 6 3 - 8 years agoHelpfull: Yes(0) No(0)
- last intialization value is taken first ..
- 8 years agoHelpfull: Yes(0) No(0)
- Garbage Value
- 7 years agoHelpfull: Yes(0) No(0)
- No. It only gives a warning ! %d needs an 'int' argument!
- 7 years agoHelpfull: Yes(0) No(0)
C Other Question