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++ 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: a
Output: 97Input: D
Output: 68
Contact Us