+ 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?... 🤔
13 ответов
+ 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
+ 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?
+ 6
JOY
Thanks once more. You seem to be the only one that gets my point. 😅
+ 5
Your logic is right!
As for validity ,I think it is right.
The results are not the same.
+ 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.
+ 4
you need only "=" you're assigning not comparing
+ 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.
+ 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
+ 4
Brahmeswara Rao:
Thanks uncle Rao 👍🏼
+ 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#)
+ 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".
+ 1
beginning too as am too much used to with the question. But I realised your logic soon
0
ابو كيان نعمان
👍🏼 🌼