in Programming in C
2,157 views
0 votes
0 votes
what is the differernce between if (a=0) and if (a= -7) or any other non-zero number e.g what will be the out put of following program

a)if ( a=0)

printf(""a is zero ")

else

printf("a is not zero")

and if we replace 0 by some +ve or -ve number  then
in Programming in C
2.2k views

1 comment

if you place any variable inside if statement like if(a) , then the body under if statement will execute till the variable is positive if a becomes zero or negative then the condition will be false.

same you can infer for other numbers too, till they hold the truth value the sub codewill be executed.
0
0

2 Answers

2 votes
2 votes

inside if  we can have (a=0) or (a==0) there is a difference

a=0 means evaluating the if expr as FALSE

where as a==0 means comparing the value of a with 0

here at first (a=0) is evaluating as false

so output will be

A is not zero

1 vote
1 vote
if (a= 0) evaluates to false

and

if (a= -ve or +ve) evalutes to true.

 

This program will print" A is not zero"

2 Comments

hi, can you explain

if(a = -7)     is evaluated as true
0
0
-7 is assigned to a and then here a is an expression in if condition and it holds -7 which is a non zero. so, the condition will be true.
0
0