C++ knowledge test
English
Advanced
Do you know everything about C++? Sure? Then this test is for you!
Description
C++, C, Cpp, Informatics, Programming, Program, Programs, Coding, Code, Codes, Computer, Computer science, CS, Programming language, Programming languages
Tags
32
Questions
30 sec
Per question
6:25
Average time
4.0
Contest Score
4.5
Community Rating
24
Participants
Educational explanations. 👍 Explanations cover why the correct answers are correct and why the wrong answers are wrong (when appropriate). E.g.: #q1, #q2, #q3
true||false&&false
states that first the operation && will be performed and that's not true. In C++ operands || and && have the same priority and are left associative, also, they are short-circuited operands, then:
true||false&&false
will be interpreted as:
true||(false&&false)
and true will be evaluated first, resulting in a trivial true and then the right of the or operator (expression at the right of ||) won't be evaluated.
1. Wikipedia link: https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence (precedence of && is higher than of ||)
2. I ran this code in an online compiler and the result is true: https://ideone.com/IUkk9z (output is 1 which means true, regardless of the order in which the operations are written)
https://en.cppreference.com/w/cpp/language/operator_precedence
That's why:
true||false&&false
becomes:
true||(false&&false)
What I states is that || operator is evaluated first, so the left of the || is evaluated first wich is trivially true and this operator is short-circuited so (false&&false) is never evaluated.
In explanation says that (false&&false) is evaluated first.
No, "(false&&false||true) = 1" as written in my link from previous comment: https://ideone.com/IUkk9z
Run this:
https://ideone.com/RlhdRP
And you'll see the left operand of || will be evaluated first and the right operand won't be evaluated :)
I see it has been raised before, I also have an issue with choose extra word questions; it's abit vague. Maybe choose one that is different or something like that may be better. Well done. Good luck:)👍