What is the output of the following program:
main( )
{
int i;
printf(ā%dā,i);
}
According to me there is no specific answer to the above code, it all depends on the memory management of the compiler, am I right???
Printable View
What is the output of the following program:
main( )
{
int i;
printf(ā%dā,i);
}
According to me there is no specific answer to the above code, it all depends on the memory management of the compiler, am I right???
I would think that it would give an error (or maybe a warning) that i was not initialized. But my C knowledge is a little rusty.
I'm going to get slammed for this.....
WHY do you keep asking these questions??!?! Do you really want to know?? Are you testing us?
=====================
This is what I got when I compiled it.
C:\Documents and Settings\Owner\Desktop\stuff.cpp(5) : error C2065: 'printf' : undeclared identifier
C:\Documents and Settings\Owner\Desktop\stuff.cpp(6) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
stuff.exe - 1 error(s), 1 warning(s)
mathgirl32, why do you keep making yourself look like an idiot? He is not testing us, he is actually asking a very interesting question if you knew atleast half of what you talk about.
harbir: This depends on how the compiler loads int i into memory and how the operating system deals with memory management. On most machines, this will print out what could be considered a kind of "random junk". Since int i will be on the stack (meaning, it will be using memory which was probably used by another program), when you printf %d it would output the value of the stack where int i is.
actually, if you'll notice, harbir asked almost the exact same question about four times now, all with new threads.Quote:
Originally posted here by Phactorial
mathgirl32, why do you keep making yourself look like an idiot? He is not testing us, he is actually asking a very interesting question if you knew atleast half of what you talk about.
as far as how interesting the question is, it's not very. i used to do c++, but then i remembered that i hate coding, but maybe you find two lines of code to be exciting. seems crazy to me, but that's your own preference. leave mathgirl32 alone.
now, watching grass grow. that's excitement.
Yep, like phactorial said...
If variable i was declared outside the main (global variable), it would however (ANSI-C) have been implicitly initialized to 0.
Mathgirl:
1- #include <stdio.h>
2- you can ignore the warning... this is just an example...
Ammo
i agree with phactorial, very interesting question.
well on my compiler, it gave some stupid number, still puzzled though.
On ANSI-C Compiler It will print a "JUNCK VAlUE" .this Value is actully the junck value present in the memory alocation to which compiler assine 'i' to.
The Correct way is to assint any value to 'i' befor printing it.
printf(?d?i);
Whate does it mean?My compiler tell me there is a syntax in the sentece.So I think you are speak rubish at all.
haha
hhk , just read it again buddy, there aint no question mark