- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Bool to int conversion in C++
Here we will see how to convert bool to int equivalent in C++. Bool is a datatype in C++, and we can use true or false keyword for it. If we want to convert bool to int, we can use typecasting. Always true value will be 1, and false value will be 0.
Example
#include <iostream> using namespace std; main() { bool my_bool; my_bool = true; cout << "The int equivalent of my_bool is: " << int(my_bool) << endl; my_bool = false; cout << "The int equivalent of my_bool is: " << int(my_bool); }
Output
The int equivalent of my_bool is: 1 The int equivalent of my_bool is: 0
Advertisements