2,146 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

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 votes
1 votes
if (a= 0) evaluates to false

and

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

 

This program will print" A is not zero"

Related questions