Home >>Cpp Programs >C++ Program to Find ASCII Value of a Character

C++ Program to Find ASCII Value of a Character

Print character through ASCII value using cout in C++

In this example, we will see a C++ program through which we can print character through ASCII value.

When we pass an integer value to cout then it prints the value in decimal format and if we want to print a character using the ASCII value then cout will not print the character normally.

We will use the cast type in this program, we can use cout<<char(var), which will print the ASCII value of (var).

Program:

#include <iostream>
using namespace std;

int main()
{
//loop counter
int i;

for(i='A'; i<='Z'; i++)
cout<<"CHAR: "<<(char)i<<" ASCII: "<<i<<endl;

return 0;
}

Output:
CHAR: A ASCII: 65
CHAR: B ASCII: 66
CHAR: C ASCII: 67
CHAR: D ASCII: 68
CHAR: E ASCII: 69
CHAR: F ASCII: 70
CHAR: G ASCII: 71
CHAR: H ASCII: 72
CHAR: I ASCII: 73
CHAR: J ASCII: 74
CHAR: K ASCII: 75
CHAR: L ASCII: 76
CHAR: M ASCII: 77
CHAR: N ASCII: 78
CHAR: O ASCII: 79
CHAR: P ASCII: 80
CHAR: Q ASCII: 81
CHAR: R ASCII: 82
CHAR: S ASCII: 83
CHAR: T ASCII: 84
CHAR: U ASCII: 85
CHAR: V ASCII: 86
CHAR: W ASCII: 87
CHAR: X ASCII: 88
CHAR: Y ASCII: 89
CHAR: Z ASCII: 90

Cpp Programs Fibonacci Series in C++ Armstrong Number in C++ Factorial program in C++ Check Palindrome in C++ Prime Number Program In C++ Reverse Number Program in C++ Sum Of Digits Program in C++ C++ Find C++ protected keyword CPP Program for different ways to print array elements CPP Program to determine the colour of chess square CPP Program to Reverse Number CPP Program to Calculate Power of a Number CPP Program to print all Even and Odd numbers from 1 to N Program to find whether a no is power of two in CPP C++ program to find largest list of prime numbers Auto keyword in Cpp C++ program to print the left Rotation of the array Convert a given binary Tree to Doubly Linked List Delete keys in a Linked list using C++ program How do you delete a linked list in C++ Implement stack with linked list in c++ C++ Program to find first occurrence of a Number Using Recursion in an array C++ program to find Last occurrence of a Number using Recursion in an array C++ Program to find Union of two singly Linked Lists Remove Duplicates from linked list in c++ C++ Program to find Nth node in Linked List Merge sort singly linked list c++ C++ Program to Convert Roman Number to Integer Number C++ Program to find LCM of two numbers C++ Password Generator C++ Program to multiply two numbers without using multiplication operator C++ Program to print all possible subset of a set Sum of all the elements in an array divisible by a given number Print First uppercase letter in a string c++ C++ Program to Find the Number Occurring Odd Number of Times C++ Program for Print address of Variable Using Pointer C++ Program to Find ASCII Value of a Character C++ Classes and Objects Program Create a class method in C++ C++ Create Empty Class Define a class method outside the class definition in C++ How to create multiple objects of a class in C++
No Sidebar ads