![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
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;
Advertisements