- Guys now a days many of us after familiar with c++ do mistakes ,Here we come up with solution.
- Daily we post tricky question here ,which will increase your way of thinking and reduce your simple mistakes
- Question : Solve the Question and post the first answer you got, in comment box .
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a = 6,b = 3;
- if(b = 5)
- b--;
- a++;
- cout<<a<<" "<<b;
- return 0;
- }
- Many of you thinks the output of this question = 7 3
- But this is totally wrong 👀💣 . You are mistaken and done wrong .
- Go through our solution and rectify you mistakes .
- Solution :
- Many of us thinks in code in line 6 b is not equals to 5 ,so if statement won't execute. Hence answer will be 7 3.
- But this is wrong ,if we observe clearly in line 6 if statement contains assignment operator ("=") not relational operator("==").
- As we can observe the code in line number 6 it is given if(b = 5) , it means it will assign 5 to b and returns true in if statement .
- So now b becomes 5 and inside if statement it will be like if( true ) .
- Hence line 7 will executes and b will be equals to 4 .
- As usual a will be come 7 in line 8 .
- Hence , the answer is 7 4