November 19th, 2002, 08:33 AM
Please give the C output
What is the output of the following program??
Every time the compiler is giving me the answer as 0. Has the compiler initialized the variable i to 0 it self, or there is some other reasoning?
November 19th, 2002, 11:51 AM
just a suggestion:
why not delete this thread and the other one you just posted about the exact same subject, and then reply to your other thread, which happens to be on the same topic as these ones? it clears up a lot of space in the forums, and it doesn't trick us in to thinking there are new threads with different subjects that we can talk about.
i will shoot you so hard.
November 19th, 2002, 12:11 PM
I assume the percent sign before the d somehow got lost.
i is an uninitialised variable. As it hasn't been initialised it won't have any particular value. It might be 0, then again it might not.
Operating systems which have multi-user capability always clear memory with zeros before giving it to a program for security, but that's no guarantee that i is zero, because it's on the stack which may have been used to run some startup code before main() was called, and hence wrote nonzero to it. You won't see data from another program, but you will see data from any libraries etc.
So it will depend on at least
- The compiler
- The OS
- The C library
- The phase of the moon
- The length of a piece of string