Skip to content

Instantly share code, notes, and snippets.

@GermanHoyos
Created January 13, 2022 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GermanHoyos/9f93910cfb7f1392a53c85e90f2926ae to your computer and use it in GitHub Desktop.
Save GermanHoyos/9f93910cfb7f1392a53c85e90f2926ae to your computer and use it in GitHub Desktop.
Type Casting Example in C++
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
int num;
cout << "Enter an integer between 0 and 35:" << endl;
cin >> num;
if (num <= 9) {
cout << num << endl;
} else {
//Example cin = '11'.... (97 + (11 - 10)) } = 98 which is "b"
cout << static_cast < char > ('A' + (num - 10)) << endl; // cast into a CHAR
// operator<dataType> (expression)
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment