Related codes are those codes where similar programming concepts are in use. They are different from alternate codes in the sense that they may not have same purpose and results.
:
Run Output
Input a character: R
ASCII of input character 82
ASCII of next character 83
char ch; cout<<“Input a character: “; cin>>ch;
Here we are collecting the user input in the char data type variable ch.
cout<<“ASCII of input character “<<(int)ch<<endl;
Here the character output is being typecasted to (int) so that its ascii code can be printed.
cout<<“ASCII of next character “<<ch+1<<endl;
Here we are adding 1 to the ch. When such mathematical operation is done on a character data type it first converted to integer ascii code and then the number is added. Now although the original variable ch remains a char data type but ch+1 will be a number and suitable ascii value shall be printed.
Notes
Casting operations can be done in function style manner in as int(ch) also.