+ 12
Explain this code
int a= 7; int b= 1; if(a=8 || b==5) cout<< a * b; cout<< " "<< a; // 1 1
11 Réponses
+ 7
Thank you all 😃
+ 6
If value of a is 8 or value of b is equal to 5 then the next line will be executed.
+ 5
🇮🇳Aditya Pardeshi 🇮🇳 stop spamming q&a is only for asking programming related questions
+ 2
It will generate an error because in the third line,
if(a=8||b==5), you can not use an assignment statement as a condition for if. a=8 is an assignment statement
+ 2
When I was begginer I posted that srry
0
if condition will be skipped because it return false, so it will execute
cout<< " "<< a; equivalent with cout<<a; where int a=7; "" empty space. The output is 7. if condition use assignment operator == instead of = to avoid certain error in c++.
- 3
if(a=8 || 1 ==5) since b =1
1==5 will return 0 (false)
And since 8 is a positive integer you can assign the value 8 to a so a=8 will return true that is 1
So 1 || 0 will return 1.
That is a*b will be 1*1 and a is also 1.
so the final answer would be 1 1