0
Sololearn coders should sharpen their knowledge. What should be the output? Sololearn says it's 20. Do you agree with them?
#include<iostream> using namespace std; int main() { int x = 10, s = 0; s = sizeof(x = x+20); cout << x << endl; return 0; }
2 Answers
+ 1
The answer should be 10. Explanation: the sizeof operator is evaluated at compile time. The compiler only needs to determine the type of the result in order to substitute the size as a literal constant, so only the left side of the assignment (=) matters, which is x, so the compiler substitutes 4 as the sizeof (int). It ignores the right side and it does not build the assignment into the run-time code.
If Sololearn claims the answer is 20 or even 30, then you should send a bug report to info@sololearn.com. The output is 10.
Where did you find this, Md Mehedi Hasan?
0
Md Mehedi Hasan ,
do you have a coding related question / issue with your code? or is it just a quizz?