/*************************************************/ // dataTypeChars.cpp // R. A. Hillyard // Last Modified: 02/07/2001 // // This program demonstartes the relationship between // char types and integers /*************************************************/ #include <iostream>
using namespace std; int main() { int i = 3; int a = 36; char letter; cout << "The variable a has a value of " << a << endl; cout << "Which represents the ACSII symbol "<< (char)a << endl; cout << "The letter A has an ASCII value of "<< (int)'A' << endl; cout << "And the letter "<< (char)('A'+1) << " has an ASCII value of " << ('A'+1) << endl; cout << endl << "Enter a letter: "; cin >> letter; cout << "you entered " << letter << endl; cout << "thats "<<(int)letter <<" in ASCII" << endl; cout << "next char is " << (char)(letter+1) << endl; i = 'A' + 'a'; cout <<endl << "'A' + 'a' = " << i << endl; i = 'A' + a; cout << endl << "'A' + a = " << i << endl; return 0; } /*******************************************************************/ The variable a has a value of 36 Which represents the ACSII symbol $ The letter A has an ASCII value of 65 And the letter B has an ASCII value of 66 Enter a letter: g you entered g thats 103 in ASCII next char is h 'A' + 'a' = 162
'A' + a = 101