what will be the output b=3; a=b++;

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • megha barde
    New Member
    • Jun 2013
    • 1

    what will be the output b=3; a=b++;

    when the following piece of code is executed,what happened?
    b=3; a=b++;
  • PreethiGowri
    New Member
    • Oct 2012
    • 126

    #2
    b is with post-increment operator in this, Post-Increment value is first used in a expression and then incremented.
    Consider an example say,

    Code:
    #include<stdio.h>
    
    void main()
    {
    int a,b=3;
    
    a = b++;
    printf("Value of a : %d",a);
    a = b++;
    printf("Value of b : %d",a);
    }
    output :
    Value of a : 3
    Value of b : 4
    Last edited by Rabbit; Jun 17 '13, 03:43 PM. Reason: Please use code tags when posting code.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Whenever you want to see the outcome of a piece of code, just write a small program and run it.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        A quick summary of terminology. The expression b++ invokes the post-increment operation. C has several variations:
        • b-- post-decrement
        • ++b pre-increment
        • --b pre-decrement

        Comment

        Working...