+ 11

C# Challenge question... ๐Ÿค”

https://www.sololearn.com/post/1335223/?ref=app Which of the following are valid, given: int x = 0; ? Select all that apply. a. 5 + x = x; b. x = x + 5; c. x += 5; d. x == x + 5; Sololearn's correct answers are b and c. Question: why is d not a correct answer?... ๐Ÿค”

20th Oct 2021, 10:36 AM
๐Ÿ‘‘ Tchybooxuur!
๐Ÿ‘‘ Tchybooxuur! - avatar
13 Answers
+ 11
== is equality operator in js we also have === to check type and value so, if you wanna add some value to a variable you gotta do it these ways: x = x + 1; or x += 1; not x == x + 1; int x = 0; Console.WriteLine(x =+ 1); => 1 Console.WriteLine(x = x + 1); => 2 Console.WriteLine(x == x + 1); => false So, you are right somehow but this.... int x = 0; x == x + 1; Console.Write(x); will give an error https://code.sololearn.com/c52vFjE7xeZH
20th Oct 2021, 10:47 AM
JOY
JOY - avatar
+ 6
Ahmed Afgooye ๐Ÿ‡ธ๐Ÿ‡ด ๐Ÿ‡ธ๐Ÿ‡ด & Sayed Thanks. I get the explanation but the question didn't state that we are comparing or just assigning values. Console.WriteLine(x == x + 5); is valid right?
20th Oct 2021, 11:45 AM
๐Ÿ‘‘ Tchybooxuur!
๐Ÿ‘‘ Tchybooxuur! - avatar
+ 6
JOY Thanks once more. You seem to be the only one that gets my point. ๐Ÿ˜…
20th Oct 2021, 11:49 AM
๐Ÿ‘‘ Tchybooxuur!
๐Ÿ‘‘ Tchybooxuur! - avatar
+ 5
Your logic is right! As for validity ,I think it is right. The results are not the same.
20th Oct 2021, 1:34 PM
Brahmeswara Rao
Brahmeswara Rao - avatar
+ 4
JOY I get that. Maybe I'm thinking too much. The question is about validity. The 2 operands are not equal and hence, the programs outputs false.
20th Oct 2021, 10:52 AM
๐Ÿ‘‘ Tchybooxuur!
๐Ÿ‘‘ Tchybooxuur! - avatar
+ 4
you need only "=" you're assigning not comparing
20th Oct 2021, 10:54 AM
Ahmed Afgooye ๐Ÿ‡ธ๐Ÿ‡ด ๐Ÿ‡ธ๐Ÿ‡ด
Ahmed Afgooye ๐Ÿ‡ธ๐Ÿ‡ด ๐Ÿ‡ธ๐Ÿ‡ด - avatar
+ 4
๐Ÿ‘‘ Tchybooxuur! (x == x + 5) is valid when we use it in condition like if (x==5) // do it But when we write it directly like x == 5 //it will throw an error.
20th Oct 2021, 11:02 AM
TOLUENE
TOLUENE - avatar
+ 4
Most welcome bro. TBH I was biased in the beginning too as am too much used to with the question. But I realised your logic soon
20th Oct 2021, 11:51 AM
JOY
JOY - avatar
+ 4
Brahmeswara Rao: Thanks uncle Rao ๐Ÿ‘๐Ÿผ
20th Oct 2021, 2:19 PM
๐Ÿ‘‘ Tchybooxuur!
๐Ÿ‘‘ Tchybooxuur! - avatar
+ 3
Danny-Durand NZIGAMASABO valid (adj): /หˆvalษชd/ 1) (of an argument or point) having a sound basis in logic or fact; reasonable or cogent. "a valid criticism" 2) based on truth or reason. Able to be accepted. int x = 0; x == x + 5; is a valid construct. The question only asks whether it's valid. It doesn't say anything else. 5 + x = x (not valid in C#)
24th Oct 2021, 8:43 AM
๐Ÿ‘‘ Tchybooxuur!
๐Ÿ‘‘ Tchybooxuur! - avatar
+ 2
"==" is equality operator, meaning "does the value at the value at the right equal to the value at the left". "=" is an assignment operator, meaning "the right value is assigned to the left one".
22nd Oct 2021, 9:52 AM
Danny-Durand NZIGAMASABO
Danny-Durand NZIGAMASABO - avatar
+ 1
beginning too as am too much used to with the question. But I realised your logic soon
7th Nov 2021, 2:43 AM
ุงุจูˆ ูƒูŠุงู† ู†ุนู…ุงู†
ุงุจูˆ ูƒูŠุงู† ู†ุนู…ุงู† - avatar
16th Nov 2021, 6:44 AM
๐Ÿ‘‘ Tchybooxuur!
๐Ÿ‘‘ Tchybooxuur! - avatar