in Programming in C
1,403 views
1 vote
1 vote
#include<stdio.h>
main()
{
    int j=0;
    int i;
    for( i=0;i<100;i++)
    {
        j=j++;
    }
    printf("%d",j);
}

why o/p is zero??
in Programming in C
1.4k views

3 Comments

answer is compiler dependent on gcc it is giving 0 and on turbo c it is giving 100.
0
0
This program output will give the ans 0 try it as j=j+1 then it will give answer as 100. So it means that it only doing 0++ in gcc compiler
0
0

https://gateoverflow.in/62411/undefined-behaviour-in-c check other examples for undefined behaviour.

1
1

1 Answer

0 votes
0 votes
Every time value of j taht is zero assign to itself j before the increment

j=j++;//at this line zero is  assign first then increment and every time j is assign by zero //

so the final output will be zero