What is difference between if(1=2} and if (1==2),in first case result is 1,in second 0, please,explain me,why ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is difference between if(1=2} and if (1==2),in first case result is 1,in second 0, please,explain me,why ??

В чем разница объясните -გთხოვთ ამიხსნათ- რაშია განსხვავება? <thanks,спасибо,მადლობა>

7th Oct 2017, 10:03 AM
pro
pro - avatar
11 Answers
+ 10
= assigns == compares if operator check a condition if condition true then reply 1 or else 0 thats why second reply 0 because 1!=2 for first reason there is a rule in c "C reply ‘true’ in non-zero always" so u assign a non zero element so its return 1 if the condition is like if(0) then its reply 0 or if(a) its return 1. hope u understand☺
7th Oct 2017, 10:26 AM
Scooby
Scooby - avatar
+ 5
then mark best answer ☺☺ i am friend of every sololearians ☺
7th Oct 2017, 10:38 AM
Scooby
Scooby - avatar
+ 4
= assigns == compares
7th Oct 2017, 10:06 AM
D_Stark
D_Stark - avatar
+ 4
ooo.. go to ur email that connected to ur sl account there is a email from sl click activate then u'll able to like ☺
7th Oct 2017, 10:51 AM
Scooby
Scooby - avatar
+ 3
@Scooby you are my friend from this moment :)
7th Oct 2017, 10:36 AM
pro
pro - avatar
+ 3
David stark you are miracle :)
7th Oct 2017, 10:38 AM
pro
pro - avatar
+ 3
@Scoobyl cann't like anyone,sololearn answers me that l am not connected,l don't understant a reason,can you suggest me something(help) once again :)
7th Oct 2017, 10:47 AM
pro
pro - avatar
+ 2
u too ♥
7th Oct 2017, 11:05 AM
Scooby
Scooby - avatar
+ 2
@luka ara dzma gavige,madloba
7th Oct 2017, 11:20 AM
pro
pro - avatar
+ 1
nice explain l will try it,thanks so much,good luck in proggraming ♡(all sololearns)♡
7th Oct 2017, 11:04 AM
pro
pro - avatar
+ 1
'if(1=2)' this is like you are assigning the value of 2 to 1 just like saying if 1 is 2 but for..that is 1 is now been giving the value of 2 so the result will be true or 1 'if(1==2)' in this case you are comparing the values..like saying if 1 is the same thing as 2... therefore '=' and '==' are two different things in c++ programming that is why for the second the result was zero because 1 is not the same thing as 2...
7th Oct 2017, 6:10 PM
Kabir Sumayya
Kabir Sumayya - avatar