+ 1
Explain the reason for the output
3 ответов
+ 6
x is a global variable.
All global variables are initialized with 0 by default.
Now inside if statement
if(x) which is equal to if(0) is evaluated as if(false) so the compiler moves to the else part of the if statement.
0 is considered as false
1 is considered as true
+ 3
Global variables are initialized to the type's default value. In this case since it is an int variable its value is defaulted to zero.
Your condition `if(x)` checks whether <x> is non zero, and given its value is zero (boolean: false) the `else` block is executed rather.
(Edit)
I didn't see an answer when I first open this thread 😁
Hth, cmiiw
+ 3
X is global variable and by default X is initialized to 0.
So, always else part is executed.
By initializing X with non-zero value, you can get value in if part.
Hope this helps...!!!