+ 12

Explain this code

int a= 7; int b= 1; if(a=8 || b==5) cout<< a * b; cout<< " "<< a; // 1 1

12th Jul 2020, 11:32 AM
Kashyap Kumar
Kashyap Kumar - avatar
11 Answers
+ 7
Thank you all šŸ˜ƒ
12th Jul 2020, 3:08 PM
Kashyap Kumar
Kashyap Kumar - avatar
+ 6
If value of a is 8 or value of b is equal to 5 then the next line will be executed.
12th Jul 2020, 12:03 PM
Arafat Hossain Ar
Arafat Hossain Ar - avatar
+ 5
šŸ‡®šŸ‡³Aditya Pardeshi šŸ‡®šŸ‡³ stop spamming q&a is only for asking programming related questions
2nd Sep 2020, 4:27 PM
RšŸšŸ‡®šŸ‡³
RšŸšŸ‡®šŸ‡³ - avatar
+ 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
15th Jul 2020, 6:52 AM
Dhruv R Jain
Dhruv R Jain - avatar
+ 2
When I was begginer I posted that srry
2nd Sep 2020, 4:29 PM
Aditya Pardeshi
Aditya Pardeshi - avatar
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++.
15th Jul 2020, 5:44 PM
Oliver Pasaribu
Oliver Pasaribu - avatar
- 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
14th Jul 2020, 5:05 AM
mithul sourav
mithul sourav - avatar