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

Course Content

C++ Introduction

C++ Introduction

1. Getting Started
2. Variables and Data Types
3. Introduction to Operators
4. Introduction to Program Flow
5. Introduction to Functions

bookLogical Operators

You have to use the logical operators NOT (!), AND (&&), and OR (||) to evaluate multiple conditions concurrently. Let's illustrate using logical operators in real-life scenarios:

  • I will take my wallet for a walk if there is a bank AND a shop on the way;
  • I won't take my wallet for a walk if there is NOT bank on the way;
  • I will take my wallet for a walk if there is a bank OR a shop on the way.
cpp

main

copy
12345678910111213141516171819
#include <iostream> int main() { bool bank = true; bool shop = true; //using AND (&&) operator bool wallet1 = (bank && shop); std::cout << "There is a bank and a shop, reason to have wallet = " << wallet1 << std::endl; //using NOT (!) operator bool wallet0 = (!bank); std::cout << "There is not bank, reason to have wallet = " << wallet0 << std::endl; //using OR (||) operator bool wallet2 = (bank || shop); std::cout << "There is a bank or a shop, reason to have wallet = " << wallet2 << std::endl; }
What will the program output?

What will the program output?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 3
some-alt