Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit efe3f1c

Browse files
[basicTypes] Remove confusing statement about operator precedence.
The question was about boolean logic, and not precedences.
1 parent 2a28193 commit efe3f1c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

‎exercises/basicTypes/basicTypes.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main() {
4545
bool condition1 = false;
4646
bool condition2 = true;
4747
print( alwaysTrue && condition1 && condition2 );
48-
print( alwaysTrue || condition1 && condition2 ); // Q: Why does operator precedence render this expression useless?
48+
print( alwaysTrue || condition1 && condition2 ); // Q: Are this and the following expressions useful?
4949
print( alwaysTrue && condition1 || condition2 );
5050
print(condition1 != condition1); // Q: What is the difference between this and the following expression?
5151
print(condition2 = !condition2);

‎exercises/basicTypes/solution/basicTypes.sol.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ int main() {
4545
bool condition1 = false;
4646
bool condition2 = true;
4747
print( alwaysTrue && condition1 && condition2 );
48-
print( alwaysTrue || condition1 && condition2 ); // Q: Why does operator precedence render this expression useless?
49-
print( alwaysTrue && condition1 || condition2 ); // A: "true || " is evaluated last. The expression therefore is always true.
48+
print( alwaysTrue || condition1 && condition2 ); // Q: Are this and the following expressions useful?
49+
// A: Not really. Since we use "true ||", it is always true.
50+
print( alwaysTrue && condition1 || condition2 ); // A: "true && condition1" is the same as "condition1"
5051
print(condition1 != condition1); // Q: What is the difference between this and the following expression?
5152
print(condition2 = !condition2); // A: The first is a comparison, the second a negation with subsequent assignment
5253
print( alwaysTrue && condition1 && condition2 );

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /