|
-
November 19th, 2002, 09:29 AM
#1
Senior Member
Please check the C code
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???
-
November 23rd, 2002, 05:54 AM
#2
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.
\"When you say best friends, it means friends forever\" Brand New
\"Best friends means I pulled the trigger
Best friends means you get what you deserve\" Taking Back Sunday
Visit alastairgrant.ca
-
November 23rd, 2002, 06:21 AM
#3
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)
-
November 23rd, 2002, 07:52 AM
#4
Member
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.
-
November 23rd, 2002, 08:19 AM
#5
Member
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.
actually, if you'll notice, harbir asked almost the exact same question about four times now, all with new threads.
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.
i will shoot you so hard.
-
November 23rd, 2002, 08:20 AM
#6
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
Credit travels up, blame travels down -- The Boss
-
November 23rd, 2002, 10:27 AM
#7
Banned
i agree with phactorial, very interesting question.
well on my compiler, it gave some stupid number, still puzzled though.
-
November 23rd, 2002, 10:53 AM
#8
Banned
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.
-
November 23rd, 2002, 01:09 PM
#9
Junior Member
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.
 [shadow]
-
November 23rd, 2002, 01:15 PM
#10
Banned
haha
hhk , just read it again buddy, there aint no question mark
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|