ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://builtin.com/articles/c-or-and |
| Last Crawled | 2026-04-09 03:11:19 (10 hours ago) |
| First Indexed | 2024-09-24 03:45:17 (1 year ago) |
| HTTP Status Code | 200 |
| Meta Title | C++ Or, And and Not Logical Operators Explained | Built In |
| Meta Description | In modern C++, or and and not are keywords that can be used to replace the boolean opeartors &&, || and !, respectively. Learn more. |
| Meta Canonical | null |
| Boilerpipe Text | In modern
C++
, you can use
and
,
or
and
not
as
boolean operators
, which means
&&
,
||
and
!
respectively. This makes them identical to languages like
Python
. These operators were in C as macros, but modern C++ introduced them as keywords.
#
include
<iostream>
int
main
()
{
std::cout <<
true
and
true
<< std::endl;
std::cout <<
true
or
false
<< std::endl;
std::cout <<
not
true
<< std::endl;
return
0
;
}
This is exactly identical to:
#
include
<iostream>
int
main
()
{
std::cout <<
true
&&
true
<< std::endl;
std::cout <<
true
||
false
<< std::endl;
std::cout << !
true
<< std::endl;
return
0
;
}
You can probably use any one of the styles depending on your codebase.
What are the C++ And, Or and Not Operators
and
,
or
and
not
are boolean operators that were introduced as keywords in modern C++. Here’s how they work:
And
: The
and
operator is equivalent to
&&
and issued to evaluate two expressions, returning
true
only if both expressions are
true
.
Or
: The or operator is equivalent to
''
and is used to evaluate two expressions, returning
true
only if one expression is
true
.
Not
: The not operator is equivalent to
!
and is used to invert boolean values.
C++ Or, And and Not Logical Operators Explained With Code
Below you’ll find an explanation of how the and, or and not operators in C++ work, along with sample code.
1. And Operator
C++
and
operator is used for boolean evaluations between boolean values. It is equivalent to
&&
operator. Both are used to evaluate two expressions and return
true
only if both expressions are
true
. Otherwise, it returns
false
.
And Operator Syntax
bool
and
bool
And Operator Code Example
#
include
<iostream>
using
namespace
std;
int
main
()
{
bool
a =
true
;
bool
b =
false
;
if
(a
and
b) {
cout <<
"Both are true"
<< endl;
}
else
{
cout <<
"One or both are false"
<< endl;
}
return
0
;
}
More on Software Engineering
STD::Optional in C++: A Guide
2.Or Operator
C++
or
operator is used for boolean evaluations between boolean values. It is equivalent to theÂ
||
operator. Both are used to evaluate two expressions and return
true
only if
one
expressions is
true
. Otherwise, it returns
false
.
Or Operator Syntax
bool
or
bool
Or Operator Code Example
#
include
<iostream>
using
namespace
std;
int
main
()
{
bool
a =
true
;
bool
b =
false
;
if
(a
or
b) {
cout <<
"One is true"
<< endl;
}
else
{
cout <<
"Both are false"
<< endl;
}
return
0
;
}
A tutorial on how to use logical operators in C++. | Video: Tech With Tim
More on Software Engineering
C++ Lambda Expressions Explained
3. Not Operator
C++
not
operator is used to invert boolean values.
Not true
becomes
false
and
not false
becomes
true
.
Not Operator Syntax
not
bool
ean_value
Not Operator Code Example
#
include
<iostream>
using
namespace
std;
int
main
()
{
bool
a =
true
;
if
(
not
a) {
cout <<
"a is now false"
<< endl;
}
else
{
cout <<
"a is still true"
<< endl;
}
return
0
;
}
Even though
and
,
or
and
not
are introduced as keywords, many codebases still use the symbolic form and these should be used when really needed.
In modern C++, the logical operators
&&
,
''
and
!
are represented as the keywords
and
,
or
and
not
respectively. They are used to compare boolean values.
The logical operators in C++ work as follows:
And
: The and keyword is used in place of
&&
to compare two values, returning
true
only if both values are
true
.
Or
: The
or
keyword is used in place of
''
and is used to compare two values, returning
true
only if one value is
true
.
Not
: The
not
keyword is used in place of
!
, allowing the user to invert boolean values. |
| Markdown | [ ](https://builtin.com/)
[In Jobs](https://builtin.com/jobs?search=)
[View All Jobs](https://builtin.com/jobs)
[For Employers](https://employers.builtin.com/?utm_medium=BIReferral&utm_source=foremployers)
[Join](https://builtin.com/auth/signup?destination=%2Farticles%2Fc-or-and)
[Log In](https://builtin.com/auth/login?destination=%2Farticles%2Fc-or-and)
- [Jobs](https://builtin.com/jobs)
- [Companies](https://builtin.com/companies)
- [Remote](https://builtin.com/jobs/remote)
- [Articles](https://builtin.com/tech-topics)
- [Salaries](https://builtin.com/salaries)
- [Best Places To Work](https://builtin.com/awards/us/2026/best-places-to-work)
- [Job Application Tracker](https://builtin.com/auth/login?destination=%2Fhome%23application-tracker-section)
- [Software Engineering Perspectives](https://builtin.com/tag/software-engineering-perspectives "Software Engineering Perspectives")
- [Expert Contributors](https://builtin.com/tag/expert-contributors "Expert Contributors")
- [Software Engineering](https://builtin.com/tag/software-engineering "Software Engineering")
- \+1
- [C++](https://builtin.com/tag/c-plus-plus "C++")
- \+3
# A Guide to C++ Or, And and Not Logical Operators
In modern C++, or and and not are keywords that can be used to replace the boolean opeartors &&, \|\| and !, respectively. Learn more.

Written by [Swastik Baranwal](https://builtin.com/authors/swastik-baranwal)
Published on Sep. 23, 2024

Image: Shutterstock / Built In

In modern [C++](https://builtin.com/software-engineering-perspectives/c-plus-plus), you can use `and`, `or` and `not` as [boolean operators](https://builtin.com/data-science/and-in-r), which means `&&`, `||` and `!` respectively. This makes them identical to languages like [Python](https://builtin.com/software-engineering-perspectives/python). These operators were in C as macros, but modern C++ introduced them as keywords.
```
#include <iostream>
int main() {
std::cout << true and true << std::endl;
std::cout << true or false << std::endl;
std::cout << not true << std::endl;
return 0;
}
```
This is exactly identical to:
```
#include <iostream>
int main() {
std::cout << true && true << std::endl;
std::cout << true || false << std::endl;
std::cout << !true << std::endl;
return 0;
}
```
You can probably use any one of the styles depending on your codebase.
## What are the C++ And, Or and Not Operators
`and`, `or` and `not` are boolean operators that were introduced as keywords in modern C++. Here’s how they work:
1. `And`: The `and` operator is equivalent to `&&` and issued to evaluate two expressions, returning `true` only if both expressions are `true`.
2. `Or`: The or operator is equivalent to `''` and is used to evaluate two expressions, returning `true` only if one expression is `true`.
3. `Not`: The not operator is equivalent to `!` and is used to invert boolean values.
## C++ Or, And and Not Logical Operators Explained With Code
Below you’ll find an explanation of how the and, or and not operators in C++ work, along with sample code.
### 1\. And Operator
C++ `and` operator is used for boolean evaluations between boolean values. It is equivalent to `&&` operator. Both are used to evaluate two expressions and return `true` only if both expressions are `true`. Otherwise, it returns `false`.
#### And Operator Syntax
```
bool and bool
```
#### And Operator Code Example
```
#include <iostream>
using namespace std;
int main() {
bool a = true;
bool b = false;
if (a and b) {
cout << "Both are true" << endl;
} else {
cout << "One or both are false" << endl;
}
return 0;
}
```
More on Software Engineering[STD::Optional in C++: A Guide](https://builtin.com/articles/stdoptional)
### 2\.Or Operator
C++ `or` operator is used for boolean evaluations between boolean values. It is equivalent to the `||` operator. Both are used to evaluate two expressions and return `true` only if one expressions is `true`. Otherwise, it returns `false`.
#### Or Operator Syntax
```
bool or bool
```
Or Operator Code Example
```
#include <iostream>
using namespace std;
int main() {
bool a = true;
bool b = false;
if (a or b) {
cout << "One is true" << endl;
} else {
cout << "Both are false" << endl;
}
return 0;
}
```
A tutorial on how to use logical operators in C++. \| Video: Tech With Tim
More on Software Engineering[C++ Lambda Expressions Explained](https://builtin.com/software-engineering-perspectives/c-plus-plus-lambda)
### 3\. Not Operator
C++ `not` operator is used to invert boolean values. `Not true` becomes `false` and `not false` becomes `true`.
#### Not Operator Syntax
```
not boolean_value
```
#### Not Operator Code Example
```
#include <iostream>
using namespace std;
int main() {
bool a = true;
if (not a) {
cout << "a is now false" << endl;
} else {
cout << "a is still true" << endl;
}
return 0;
}
```
Even though `and`, `or` and `not` are introduced as keywords, many codebases still use the symbolic form and these should be used when really needed.
## Frequently Asked Questions
### What are the logical operators in C++?
In modern C++, the logical operators `&&`, `''` and `!` are represented as the keywords `and`, `or` and `not` respectively. They are used to compare boolean values.
### How do logical operators work in C++?
The logical operators in C++ work as follows:
- `And`: The and keyword is used in place of `&&` to compare two values, returning `true` only if both values are `true`.
- `Or`: The `or` keyword is used in place of `''` and is used to compare two values, returning `true` only if one value is `true`.
- `Not`: The `not` keyword is used in place of `!`, allowing the user to invert boolean values.
### Recent Software Engineering Perspectives Articles
[ 42 Companies Hiring Entry-Level Engineers](https://builtin.com/articles/companies-hiring-engineers-entry-level)
[ 127 SaaS Companies to Know](https://builtin.com/articles/saas-companies)
[ 103 Software Development Companies Innovating Tech](https://builtin.com/articles/software-development-companies)
Explore Job Matches.
Job Title or Keyword
Clear search
Location
Fully Remote, Hybrid, On Site
Fully Remote
Hybrid
On Site
Clear
Apply
See Jobs
- [Jobs](https://builtin.com/jobs)
- [Companies](https://builtin.com/companies)
- [Articles](https://builtin.com/tech-topics)
- [Tracker](https://builtin.com/auth/login?destination=%2Fhome%23application-tracker-section)
- More

[Join](https://builtin.com/auth/signup?destination=%2Farticles%2Fc-or-and)
[Log In](https://builtin.com/auth/login?destination=%2Farticles%2Fc-or-and)
- [Tech Jobs](https://builtin.com/jobs)
- [Companies](https://builtin.com/companies)
- [Articles](https://builtin.com/tech-topics)
- [Remote](https://builtin.com/jobs/remote)
- [Salaries](https://builtin.com/salaries)
- [Best Places To Work](https://builtin.com/awards/us/2026/best-places-to-work)
- [Tech Hubs](https://builtin.com/tech-hubs)
[Post Job](https://employers.builtin.com/membership?utm_medium=BIReferral&utm_source=foremployers)
[](https://builtin.com/)

Built In is the online community for startups and tech companies. Find startup jobs, tech news and events.
About
[Our Story](https://builtin.com/our-story)
[Careers](https://employers.builtin.com/careers/)
[Our Staff Writers](https://builtin.com/our-staff)
[Content Descriptions](https://builtin.com/content-descriptions)
***
Get Involved
[Recruit With Built In](https://employers.builtin.com/membership?utm_medium=BIReferral&utm_source=foremployers)
[Become an Expert Contributor](https://builtin.com/expert-contributors)
***
Resources
[Customer Support](https://knowledgebase.builtin.com/s/)
[Share Feedback](https://form.jotform.com/223044927257054)
[Report a Bug](https://knowledgebase.builtin.com/s/contactsupport)
[Tech Job Tools + Career Resources](https://builtin.com/articles/grow-your-career)
[Browse Jobs](https://builtin.com/browse-jobs)
[Tech A-Z](https://builtin.com/tech-dictionary)
***
Tech Hubs
[Our Sites](https://builtin.com/our-sites)
***
[Learning Lab User Agreement](https://builtin.com/learning-lab-user-agreement) [Accessibility Statement](https://builtin.com/accessibility-statement) [Copyright Policy](https://builtin.com/copyright-policy) [Privacy Policy](https://builtin.com/privacy-policy) [Terms of Use](https://builtin.com/community-terms-of-use) [Your Privacy Choices/Cookie Settings](https://builtin.com/california-do-not-sell-my-information) [CA Notice of Collection](https://builtin.com/ca-notice-collection)
© Built In 2026 |
| Readable Markdown | In modern [C++](https://builtin.com/software-engineering-perspectives/c-plus-plus), you can use `and`, `or` and `not` as [boolean operators](https://builtin.com/data-science/and-in-r), which means `&&`, `||` and `!` respectively. This makes them identical to languages like [Python](https://builtin.com/software-engineering-perspectives/python). These operators were in C as macros, but modern C++ introduced them as keywords.
```
#include <iostream>
int main() {
std::cout << true and true << std::endl;
std::cout << true or false << std::endl;
std::cout << not true << std::endl;
return 0;
}
```
This is exactly identical to:
```
#include <iostream>
int main() {
std::cout << true && true << std::endl;
std::cout << true || false << std::endl;
std::cout << !true << std::endl;
return 0;
}
```
You can probably use any one of the styles depending on your codebase.
## What are the C++ And, Or and Not Operators
`and`, `or` and `not` are boolean operators that were introduced as keywords in modern C++. Here’s how they work:
1. `And`: The `and` operator is equivalent to `&&` and issued to evaluate two expressions, returning `true` only if both expressions are `true`.
2. `Or`: The or operator is equivalent to `''` and is used to evaluate two expressions, returning `true` only if one expression is `true`.
3. `Not`: The not operator is equivalent to `!` and is used to invert boolean values.
## C++ Or, And and Not Logical Operators Explained With Code
Below you’ll find an explanation of how the and, or and not operators in C++ work, along with sample code.
### 1\. And Operator
C++ `and` operator is used for boolean evaluations between boolean values. It is equivalent to `&&` operator. Both are used to evaluate two expressions and return `true` only if both expressions are `true`. Otherwise, it returns `false`.
#### And Operator Syntax
```
bool and bool
```
#### And Operator Code Example
```
#include <iostream>
using namespace std;
int main() {
bool a = true;
bool b = false;
if (a and b) {
cout << "Both are true" << endl;
} else {
cout << "One or both are false" << endl;
}
return 0;
}
```
More on Software Engineering[STD::Optional in C++: A Guide](https://builtin.com/articles/stdoptional)
### 2\.Or Operator
C++ `or` operator is used for boolean evaluations between boolean values. It is equivalent to the `||` operator. Both are used to evaluate two expressions and return `true` only if one expressions is `true`. Otherwise, it returns `false`.
#### Or Operator Syntax
```
bool or bool
```
Or Operator Code Example
```
#include <iostream>
using namespace std;
int main() {
bool a = true;
bool b = false;
if (a or b) {
cout << "One is true" << endl;
} else {
cout << "Both are false" << endl;
}
return 0;
}
```
A tutorial on how to use logical operators in C++. \| Video: Tech With Tim
More on Software Engineering[C++ Lambda Expressions Explained](https://builtin.com/software-engineering-perspectives/c-plus-plus-lambda)
### 3\. Not Operator
C++ `not` operator is used to invert boolean values. `Not true` becomes `false` and `not false` becomes `true`.
#### Not Operator Syntax
```
not boolean_value
```
#### Not Operator Code Example
```
#include <iostream>
using namespace std;
int main() {
bool a = true;
if (not a) {
cout << "a is now false" << endl;
} else {
cout << "a is still true" << endl;
}
return 0;
}
```
Even though `and`, `or` and `not` are introduced as keywords, many codebases still use the symbolic form and these should be used when really needed.
In modern C++, the logical operators `&&`, `''` and `!` are represented as the keywords `and`, `or` and `not` respectively. They are used to compare boolean values.
The logical operators in C++ work as follows:
- `And`: The and keyword is used in place of `&&` to compare two values, returning `true` only if both values are `true`.
- `Or`: The `or` keyword is used in place of `''` and is used to compare two values, returning `true` only if one value is `true`.
- `Not`: The `not` keyword is used in place of `!`, allowing the user to invert boolean values. |
| Shard | 169 (laksa) |
| Root Hash | 7607033694470393769 |
| Unparsed URL | com,builtin!/articles/c-or-and s443 |