
- 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
C++ Program to Find ASCII Value of a Character
There are 128 characters in the ASCII (American Standard Code for Information Interchange) table with values ranging from 0 to 127.
Some of the ASCII values of different characters are as follows −
Character | ASCII Value |
---|---|
A | 65 |
a | 97 |
Z | 90 |
z | 122 |
$ | 36 |
& | 38 |
? | 63 |
A program that finds the ASCII value of a character is given as follows −
Example
#include <iostream> using namespace std; void printASCII(char c) { int i = c; cout<<"The ASCII value of "<<c<<" is "<<i<<endl; } int main() { printASCII('A'); printASCII('a'); printASCII('Z'); printASCII('z'); printASCII('$'); printASCII('&'); printASCII('?'); return 0; }
Output
The ASCII value of A is 65 The ASCII value of a is 97 The ASCII value of Z is 90 The ASCII value of z is 122 The ASCII value of $ is 36 The ASCII value of & is 38 The ASCII value of ? is 63
In the above program, the function printASCII() prints the ASCII values of characters. This function defines an int variable i and the value of the character c is stored into this variable. Since i is integer type, the corresponding ASCII code of the character is stored into i. Then the values of c and i are displayed.
This is demonstrated by the following code snippet.
void printASCII(char c) { int i = c; cout<<"The ASCII value of "<<c<<" is "<<i<<endl; }
- Related Articles
- Java program to print ASCII value of a particular character
- How to Find ASCII Value of Character using Python?
- Find the ASCII value of the uppercase character ‘A’ using implicit conversion in C language?
- Java Program to check whether the entered value is ASCII 7-bit control character
- Convert an int to ASCII character in C/C++
- C++ Program to find out the health of a character
- Java Program to check whether the character is ASCII 7 bit
- Java Program to check whether the entered character is ASCII 7 bit numeric and character
- C Program to find maximum occurrence of character in a string
- C Program to find minimum occurrence of character in a string
- C++ Program to Find the Frequency of a Character in a String
- C++ Program to find the Shortest Distance to a character
- Java Program to check whether the character is ASCII 7 bit numeric
- Java Program to check whether the character is ASCII 7 bit printable
- C# Program to find number of occurrence of a character in a String

Advertisements