int a=9,b=6,c=3;
printf("%d%d%d");
I executed this in code blocks 10.05. I got some garbage values. But in a website the output was given as 3 6 9. What is the correct one?
int a=9,b=6,c=3;
printf("%d%d%d");
I executed this in code blocks 10.05. I got some garbage values. But in a website the output was given as 3 6 9. What is the correct one?
You will get garbage values, because you're not providing any arguments to the printf() call.
The correct code would be
printf("%d%d%d",c,b,a);
(to get the numbers in the order quoted)
The correct one is neither of the two you described. Since no values were passed to printf
, only the formatters, whatever was on the stack at that moment (which is undefined) is passed.
What is the correct output of this statement?
This code invokes undefined behaviour and so there is no correct output. The output is undefined.
The code invokes undefined behaviour because the format string you passed to printf
requires you to pass more parameters (3) than you supplied (0).