ASCII Value For Each Character in a String

Below is the C++ program to print the ASCII value of each character in a string:

C++
// C++ program to print ASCII
// value of each character in a string
#include<iostream>
using namespace std;

// Driver code
int main()
{
    char ch, str[200] = "w3wiki";
    int i = 0, val;
    
    cout << "\nCharacter\tASCII Value\n";
    while(str[i])
    {
        ch = str[i];
        val = ch;
        cout << ch << "\t\t\t" << val << endl;
        i++;
    }
    cout << endl;
    return 0;
}

Output
Character    ASCII Value
G            71
e            101
e            101
k            107
s            115
f            102
o            111
r            114
G            71
e            101
e            101
k            107
s            115

C++ Program To Print ASCII Value of a Character

Given a character, we need to print its ASCII value in C++. 

Examples:

Input:
Output: 97

Input: D
Output: 68

Similar Reads

Using Type Conversion

Here int() is used to convert a character to its ASCII value. Below is the C++ program to implement the above approach:...

ASCII Value For Each Character in a String

Below is the C++ program to print the ASCII value of each character in a string:...

ASCII Value of All Characters

Below is the C++ program to print the ASCII value of all the characters:...

Contact Us