If else in c++

Hi guys ,
in c++ programming (if) when we use "=" isntead of "==" compiler behave the same ... Do u know why compiler Behave like this ??
Tnx

Questions by Seniorija

Showing Answers 1 - 1 of 1 Answers

C++ compiler treat Zero(0) as false and all nonzero value as true.
Consider the case 1:
if(val=20) //implicitly it becomes if(20)
{
cout<<"Control comes here.";
}
Case 2:
val=5;
if(val==5) //implicitly it becomes if(1) as condition is true
{
cout<<"here control comes.";
}

vinodh

  • Dec 11th, 2012
 

in the first if condition want to place double equal.then it will treat as condition.otherwise it will treat as declaration

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.