Please give the C output
Results 1 to 3 of 3

Thread: Please give the C output

  1. #1
    Senior Member
    Join Date
    Dec 2001

    Please give the C output

    What is the output of the following program??

    int i;
    main( )

    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?

  2. #2
    Join Date
    Nov 2002
    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.

  3. #3
    Senior Member
    Join Date
    Jan 2002
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts