wrong output

Discussion in 'C Programming' started by Vaibhav87@gmail.com, Sep 13, 2006.

  1. Guest

    i write
    void main()
    {
    int j;
    j - = 0;
    printf("%d",y);
    }
    & i got the answer as 842. i tried it on various computers but the
    answer is same. pls help me
    how is this answer is?
     
    , Sep 13, 2006
    #1
    1. Advertising

  2. Nelu Guest

    wrote:
    > i write
    > void main()


    int main(void)

    > {
    > int j;


    j is not initialized. Who knows what's in there.

    > j - = 0;
    > printf("%d",y);


    return 0;

    > }
    > & i got the answer as 842.


    I got 1075098164.

    i tried it on various computers but the
    > answer is same. pls help me
    > how is this answer is?
    >


    read the previous comment (j is not initialized).

    --
    Ioan - Ciprian Tandau
    tandau _at_ freeshell _dot_ org (hope it's not too late)
    (... and that it still works...)
     
    Nelu, Sep 13, 2006
    #2
    1. Advertising

  3. osmium Guest

    <> wrote:

    >i write
    > void main()
    > {
    > int j;
    > j - = 0;


    I wouldn't expect that to compile with a space between the two operators.

    It makes no sense to do arithmetic on an unknown value.


    > printf("%d",y);


    Where is y declared?

    Are you sure you're using cut and paste?

    > }
    > & i got the answer as 842. i tried it on various computers but the
    > answer is same. pls help me
    > how is this answer is?
    >
     
    osmium, Sep 13, 2006
    #3
  4. CBFalconer Guest

    "" wrote:
    >
    > i write
    > void main()

    *** ERROR - main return int.
    > {
    > int j;
    > j - = 0;

    *** ERROR unknown syntax
    > printf("%d",y);

    *** ERROR y undefined
    > }

    *** ERROR failure to return exit status.

    > & i got the answer as 842. i tried it on various computers but the
    > answer is same. pls help me
    > how is this answer is?


    What's wrong with the answer? Anything is legal when the behaviour
    is undefined.

    --
    "I have a creative mind. You (singular) are eccentric.
    He is insane. We are losing sight of reality.
    You (plural) are smoking crack. They are certifiable."
    Declension of verbs, per Lewin Edwards



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Sep 13, 2006
    #4
  5. "" <> writes:
    > i write
    > void main()
    > {
    > int j;
    > j - = 0;
    > printf("%d",y);
    > }
    > & i got the answer as 842. i tried it on various computers but the
    > answer is same. pls help me
    > how is this answer is?


    That code doesn't even compile, and it's almost certainly *not* the
    code that you actually tried. Are you expecting us to guess what your
    real program looks like?

    Copy and paste the *exact* code that you actually compiled.

    main() returns int, not void. Change "void main()" to "int main(void)".

    "j - = 0;" is a syntax error. I won't try to guess what you actually
    meant.

    You try to print the value of y, but you never declared it.

    Since you use printf() you need to add "#include <stdio.h>" to the top
    of your program.

    Since main returns an int, you should return an int: add "return 0;"
    after the printf call. (This isn't always required, but it's always a
    good idea.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Sep 13, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dimitre Novatchev

    Re: No output? What's wrong?

    Dimitre Novatchev, Jul 29, 2003, in forum: XML
    Replies:
    5
    Views:
    437
    chris
    Jul 30, 2003
  2. Matthew
    Replies:
    7
    Views:
    729
    Priscilla Walmsley
    Jan 7, 2005
  3. Alex Vinokur
    Replies:
    1
    Views:
    450
    Alf P. Steinbach
    Sep 27, 2004
  4. Blankdraw
    Replies:
    3
    Views:
    397
    Pieter Droogendijk
    Aug 10, 2003
  5. Peter Møllerud
    Replies:
    2
    Views:
    957
    Stefan Behnel
    Sep 9, 2006
Loading...

Share This Page