The term ASCII (American Standard Code for Information Interchange) refers to a defined character encoding. It assigns certain codes to characters such as letters, digits and punctuation marks. The ASCII code is used to specify how the characters are displayed by electronic devices – such as PCs or smartphones. This is an important part of many programming operations
#include <iostream>
using namespace std;
int main () {
char c;
cout << "Please enter character: ";
cin >> c;
cout << "ASCII value of the character " << c << " is: " << int(c);
return 0;
}
Please enter character: u
ASCII value of the character u is: 117
char c;
cout << "Please enter character: ";
cin >> c;
c
of type char
is declared to store the character entered by the user.cout
, which outputs the prompt to the standard output. Following the prompt, cin
is used to read the single character entered by the user and store it in the variable c
.cout << "ASCII value of the character " << c << " is: " << int(c);
c
. It constructs a message that includes the character and its ASCII value.int(c)
is a type cast that converts the char
value in c
to its corresponding integer value, which is the ASCII code of the character.return 0;
return 0;
statement is used to indicate that the program has finished executing successfully. It returns an exit status of 0 to the operating system, signifying a successful completion.