#include #include void main() { int a=10,b=20; printf("%d %d"); getch(); } the output is 20 10. How it is possible?
#include #include void main() { int a=10,b=20; printf("%d %d"); getch(); } the output is 20 10. How it is possible?
you must write it as
printf("%d %d",a,b);
or it may also happen that you have written
printf("%d %d",b,a);
if u r written exactly the code u r showing then its not known what value is printed cuz its just compiler dependent that when it does not find the value to be printed for a format specifier, then what shud it do?
and otherwise if u have written printf("%d%d",b,a);
then the result is right.
for the above code "printf("%d %d");" you will get the output as 0 0 and not 20 10.
I have validated the same on VS2005.
If you are getting outpur as 20 10 then you must have used "printf("%d %d", b , a);" for sure. DFo validate your code please.
If u do not provide any arguments for the format specifier in the printf statement, then it outputs any garbage value depending on the data type 0f the specifier.
mainly it depends on the compiler and if we not pass any arguments it give garbage values
In turbo C++ version 4.5 , in which we can run both C++ and C programs shows the same warnings and does not execute either as C program or C++ program
the warnings are same in both languages
a is assigned a value that is never used in function main()
b is assigned a value that is never used in function main()
ya i also got that output only but it is not dependable one if u want a specified output use printf with corresponding arguments only you may get the correct output without using the arguments but it is not dependable. i think the reason is: printf prints garbage value present in random memory space if u did not specify arguments then while selecting the random memory address to print a value, it selects the last accessed memory address which happens to be the memory address of A and B (those memory only got created when we declare that).
when the valuesare being assigned to the variables a and b. they get stored in the stack segment as u know popping take place in LIFO manner in printf statement is b is printed first and then a.
i hope the answer is correct.
i want to know about power of two numbers progam without using math.h directory in the program
The reason is that the value get store in stack, as u have not given the name of variable while using printf. the values just get pop and the last value print at first and the second one at the last.
But in the some complier it print the garbage value.
Actually if you don't use any variable in printf,then the values of a and b which are given earlier are stored in a stack,and on printf statement they are retreived in the LIFO manner.Thats why they are displayed in the opposite order.