1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what will be the output of code?

Discussion in 'C' started by imported_crmahato, Mar 12, 2010.

  1. imported_crmahato

    imported_crmahato New Member

    Joined:
    Mar 9, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    void main()
    {
      int i=10,sum=0;
      sum = ++i + ++i + ++i;
      printf("sum = %d", sum);
    }
    
    void main()
    {
      int i =10,sum=0;
      sum= i++ + i++ + i++;
      printf("sum=%d",sum);
    }
     
  2. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    Your first output will be Sum=39
    and second is Sum=30
     
  3. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    Another thing, do not post this type of code, put codes within
    [CODE ] [/ CODE] and please post full codes with header files and getch(); also. While posting two codes within a post, please seperate them!
    thanks!
    nice question!
    :D
     
  4. marck_don

    marck_don New Member

    Joined:
    May 4, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hey guys i m agree with pankaj.sea. great answer
    and thanks for sharing
     
  5. fourier

    fourier New Member

    Joined:
    Jun 24, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    output of first code is
    sum=33
    output of second code is
    sum=0
     
  6. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    I really doubt on those no matter what compiler convention be.
     
  7. fourier

    fourier New Member

    Joined:
    Jun 24, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    for this scenario the operations of prefix and postfix are not clear but for
    someother cases results can be different
     
  8. mahesh

    mahesh New Member

    Joined:
    Jun 30, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Ans 1: 39
    2:30
     

Share This Page