+ 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

9th Jan 2021, 7:55 PM
T H
5 Respostas
+ 5
The a cannot be compared with = only with == as follows: if (a == 6 || b>11)
9th Jan 2021, 7:57 PM
JaScript
JaScript - avatar
+ 4
Hi T H , = use to assign the value. == compare the value. https://code.sololearn.com/cKfu217r6rIq/?ref=app
9th Jan 2021, 7:59 PM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar
+ 2
Thanks :)
9th Jan 2021, 7:59 PM
T H
+ 2
In if condition, You should have to write a==6 . This is common mistake done by beginners. Take care 🤗
10th Jan 2021, 4:33 AM
Ashish Gupta
Ashish Gupta - avatar
+ 1
= is for assigning and == to compare , happened to me alot back then 😂 goodluck
11th Jan 2021, 7:12 PM
Yassir Rchi
Yassir Rchi - avatar