Q:

How do char and int work in C++

May be I'm going to ask a stupid question, but I want to confirm that how char works? Let me explain with examples what i want to ask.
Let suppose I declare a char variable and then input 6 or any integer character.
#include <iostream>
using namespace std;
int main(){
    char a;
    cin >> a;
    cout << a*a; // I know here input's ASCII value will multiply
    return 0;
}

Same as for integer input 6
#include <iostream>
using namespace std;
int main(){
    int a;
    cin >> a;
    cout << a*a; // Why compiler not take input's ASCII Value here?
    return 0;
}

I think now my question is clear.

A:

char is a fundamental data type, of size 1 byte (not necessarily 8bits!!!), capable of representing at least the ASCII code range of all characters. So, for example, char x = 'a'; really stores the ASCII value of 'a', in this case 97. However, the ostream operators are overloaded so they "know" how to deal with char, and instead of blindly displaying 97 in a line like cout << x; they display the ASCII representation of the character, i.e. 'a'. 
However, whenever you do a * a, the compiler performs what's called integral promotion, and implicitly converts the data in the char to an int. So, for the compiler, the expression a * a is translated into (int)a * (int)a, which is the result of 97 * 97, so you end up displaying 9409.
Note that for the compiler char and int are two different types. It can differentiate between the two. So operator<< displays a character only when the input is of type char  or of a type implicitly convertible to char.

