383 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 

 

1 Answer

Best answer
0 votes
0 votes

Related questions

0 votes
0 votes
2 answers
1
Lakshman Bhaiya asked Apr 21, 2018
2,528 views
Q) What is the output of the following C Program fragment#include<stdio.h>int main(){int a = 4, b = 3;printf("%d",a+++++b);return 0;} A) 7 B) 8 C) 9 ...
0 votes
0 votes
0 answers
2
rahul sharma 5 asked Aug 25, 2017
378 views
What is the input and output of increment/decrement operator in the C language in terms of rvalue and lvalue?
0 votes
0 votes
0 answers
3
sadiashafaque asked Aug 6, 2018
340 views
What is the output of this code in c?int main(){static int a[] [3]={0,1,2,3,4,5,6,7,8,9,10,11,12};int i=-1;int d;d=a[i++][++i][++i]; printf("%d",d); return 0;} how did 2 ...
0 votes
0 votes
3 answers
4
mamta beniwal asked Jun 13, 2018
563 views
if x=y=z=-1then the values of x,y,z after++x && ++y ||++z is shown as x=0,y=-1, and z=0 Please explain the reason behind this as I am not getting the reason of z=0.