Thread: what will be the output and plz explain me

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    1

    Smile what will be the output and plz explain me

    Code:
    #include<stdio.h>
    void main()
    {
      int i=-1,m;
      m=i++;
      printf("%d %d",i,m);
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    The output will be 0 and -1...

    This is because of the m = i++ line... m is assigned the value of I (-1) and then I is incremented to 0.

    FWIW... the correct form of main is... int main (void) ... and C programs always return a value to the operating system on exit...

    Code:
    #include<stdio.h>
    
    int main (void)
      {
        int i=-1,m;
        m = i++;
        printf("%d %d",i,m);
    
      return 0;
    }

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by alekhya k View Post
    Code:
    #include<stdio.h>
    void main()
    {
      int i=-1,m;
      m=i++;
      printf("%d %d",i,m);
    }
    >What will be the output ehh?
    Why couldn't you try compiler it to youself and see? Was it that hard to do it?

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by ssharish2005 View Post
    >What will be the output ehh?
    Why couldn't you try compiler it to youself and see? Was it that hard to do it?

    ssharish
    It's probably a fair guess that he has done just that but didn't understand the answer he got...

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    But he never put it that way did he? He asked whats the output. Perhaps he could have been much smarter in asking questions.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by ssharish2005 View Post
    But he never put it that way did he? He asked whats the output. Perhaps he could have been much smarter in asking questions.

    ssharish
    Yes he could have... but the question was sincere, he wanted to know what was going on...
    I see no problem with giving him an answer.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I see no problem with giving him an answer.
    I second this. I am assuming the poster is relatively new to programming, and the pre/post increment operator can lead to confusing problems if you don't understand the subtle difference between them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is the program output please explain
    By sunil17 in forum C Programming
    Replies: 2
    Last Post: 09-02-2010, 08:34 AM
  2. help: please explain the output
    By soniclavier in forum C Programming
    Replies: 8
    Last Post: 12-07-2009, 12:35 PM
  3. plz explain the output of the program.
    By raj_ksrt in forum C++ Programming
    Replies: 2
    Last Post: 05-26-2008, 03:43 AM
  4. Input & Output Explain?
    By 98dodgeneondohc in forum C Programming
    Replies: 5
    Last Post: 04-24-2005, 06:13 PM
  5. Explain the output of the C program
    By abacus00 in forum C Programming
    Replies: 0
    Last Post: 03-24-2003, 06:24 PM