+ 2
C language problem. Help please
/*The output of this code is confusing me a lot.*/ int main () { int a = 2; int b=7; if (a = 6 || b>11) printf("Hello World"); else printf ("Hi World"); } Output : Hello World As you can see that both the conditions in the if statement is false i.e, a is not equal to 6 and b is not greater than 11. Then why is the if statement being executed instead of the else statement? https://code.sololearn.com/coswvWbsAcDZ/?ref=app
5 odpowiedzi
+ 5
The a cannot be compared with = only with == as follows:
if (a == 6 || b>11)
+ 4
Hi T H ,
= use to assign the value.
== compare the value.
https://code.sololearn.com/cKfu217r6rIq/?ref=app
+ 2
Thanks :)
+ 2
In if condition, You should have to write a==6 .
This is common mistake done by beginners.
Take care 🤗
+ 1
= is for assigning and == to compare , happened to me alot back then 😂 goodluck