wrong output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vaibhav87@gmail.com

    #1

    wrong output

    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?

  • Nelu

    #2
    Re: wrong output

    Vaibhav87@gmail .com 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...)

    Comment

    • osmium

      #3
      Re: wrong output

      <Vaibhav87@gmai l.comwrote:
      >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?
      >

      Comment

      • CBFalconer

        #4
        Re: wrong output

        "Vaibhav87@gmai l.com" 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

        Comment

        • Keith Thompson

          #5
          Re: wrong output

          "Vaibhav87@gmai l.com" <Vaibhav87@gmai l.comwrites:
          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_Keit h) kst-u@mib.org <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.

          Comment

          Working...