
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to convert a single char into an int in C++
The following is an example to convert a character into int.
Example
#include <iostream> using namespace std; int main() { char c = '8'; int i = c - 48; cout << i; i = c - '0'; cout <<"\t" << i; return 0; }
Output
8 8
In the above program, a character ‘c’ is initialized with a value. The character is converted into integer value as shown below −
char c = '8'; int i = c - 48; cout << i; i = c - '0'; cout <<"\t" << i;
- Related Articles
- How do I convert a char to an int in C and C++?
- How to convert a String into int in Java?
- How to convert a string into int in C#?
- Swift Program to Convert Char type variables to Int
- Haskell Program to convert int type variables to char
- How to convert hex string into int in Python?
- How to convert an std::string to const char* or char* in C++?
- How to convert a String to an int in Java
- Golang Program to Convert Char Type Variables to Int Using Inbuilt Functions
- How to convert a Java String to an Int?
- How to convert columns of an R data frame into a single vector?
- How to convert multiple columns into single column in an R data frame?
- How to convert an int to string in C++?
- How to convert date and time into int in Android sqlite?
- How to assign int value to char variable in Java

Advertisements