Studytonight is now part of the GUVI universe. Explore GUVI →
🤩 New Cool Developer Tools for you. Explore →
FREE JavaScript Video Series Start Learning →
Signup/Sign In
Tests
MCQs to test your knowledge.
Compilers
Compilers to execute code in browser.
Index
LAST UPDATED: OCTOBER 9, 2020

C++ Find the ASCII value of the Character Program

Hello Everyone!

In this tutorial, we will learn how to find the ASCII value of the given Character, in the C++ programming language.

Program Logic:

This can be done easily by making use of the concept of Type-Casting.

Type-Casting refers to changing the data type of the variable while accessing it.

Example: If a variable v is of type double, it's integral value can be accessed by the following code:

int a = (int) v;

For better understanding, refer to the code given below:

Code:

#include <iostream>
using namespace std;
int main()
{
 //variable declaration - a char variable takes a single character as input
 char c;
 cout << "\n\nWelcome to Studytonight :-)\n\n\n";
 cout << " ===== Program to Find the ASCII value of a character ===== \n\n";
 //take user input
 cout << "Enter a character : ";
 cin >> c;
 //printing the ASCII value of the entered character
 cout << "\nThe ASCII value of the entered character is : " << (int)c << "\n\n";
 return 0;
}

Output:

C++ ascii

We hope that this post helped you develop a better understanding of the concept of finding the type-casting in determining the ASCII value of the character, in C++. For any query, feel free to reach out to us via the comments section down below.

Keep Learning : )



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.

Learn to Code
Learn and practice coding side-by-side.
NEW
C language Course
115+ coding exercises
Javascript Course
85+ coding exercises

AltStyle によって変換されたページ (->オリジナル) /