Casting Char to Int in C++

C++ Program to cast char to int

Source code :

#include <iostream>

using namespace std;

int main(){
    
    char c = '1';
    int i = c - '0';
    
    cout<< i <<"\n";
    cout<<"Size of i is " << sizeof(i);

    return 0;

}

Output :

1
Size of i is 4

Notes :

The size of i will be 4 since it was casted to int.


Output :


                

Comments :