Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Logical Operators | Section
/
C++ Introduction

bookLogical Operators

メニューを表示するにはスワイプしてください

You can use logical operators AND (&&), OR (||) and NOT (!) to evaluate multiple conditions simultaneously.

  • AND (&&) returns true only if both conditions are true. For example, checking if an account balance is sufficient and the withdrawal amount is positive;

  • OR (||) returns true if at least one condition is true. For example, checking if a balance is sufficient or the user has a credit card;

  • NOT (!) negates a condition, turning true into false and vice versa. For example, checking if an account is not locked.

Imagine you need to create conditions for user authentication.

logical_and.h

logical_and.h

logical_or.h

logical_or.h

logical_not.h

logical_not.h

copy
12345678910
#include <iostream> int main() { // Using AND (&&) operator for password and login // Login is correct = `true` // Password is correct = `true` std::cout << "User authorized (password AND login correct)" << (true && true) << std::endl; }

1. Which logical operator is used to check if both conditions are true?

2. Which logical operator is used to check if at least one condition is true?

3. What does the ! operator do?

question mark

Which logical operator is used to check if both conditions are true?

正しい答えを選んでください

question mark

Which logical operator is used to check if at least one condition is true?

正しい答えを選んでください

question mark

What does the ! operator do?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  9

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  9
some-alt