in Programming in C
401 views
0 votes
0 votes

The output of this program comes out to be 0,

Why not 1?

Because:

  1.  a=0;will be assigned  then a++;
  2. So now 0 will be 1; a=1; 

This freaks me out !!

#include <stdio.h>

int main()
{
    int a=0;
    a=a++;
    printf("%d",a);

    return 0;
}

 

Output:

0                                                                                                                                              

...Program finished with exit code 0 

 

in Programming in C
401 views

1 Answer

0 votes
0 votes

3 Comments

Then,

assign value :  a=a++;  ===>  a=0

then increment   a++    a=1;

 Again the same!
0
0
I updated my answer
0
0

So, this is it : Thank you

b++ is the same as:

int tmp = b;
b = b + 1;
b = tmp;
1
1

Related questions