GeeksforGeeks » Interview Questions
if else
(6 posts)-
int a=10,b=10;
if(a=b)
cout<<"equal";
else
cout<<"Not Equal";output:
Not equal -
Use "==" instead of "=" in if condition.
int a=10, b=10; if(a==b) cout<<"equal"; else cout<<"Not Equal";
-
output should be "equal"..
can any one explain why Not equal is given as o/p here -
I think you are getting confused.
The following program prints "equal"
#include<iostream> using namespace std; int main() { int a=10, b=10; if(a==b) cout<<"equal"; else cout<<"Not Equal"; return 0; }In your original program, you were using = instead of ==
-
The question itself is wrong, whether you use '=' or '==', you get the same output for a=10, b=10(not zero values of a &b).
-
output will be 'equal' inside the if() condition assignment operation is happen it will take true condition.
so it will print equal.
Reply
You must log in to post.