C++ Character Type Program

Character type variables have the data type char. And the value is assigned using the apostrophe(‘). You can use type cast (int) to get the integral value of the character. Character is an integer type. So when you type cast it, you get the corresponding value as ASCII value of literal.

using namespace std;
int main(){
	char c = 'A';
	cout<<"c = "<<c<<endl;
	c = 't';
	cout<<"c = "<<c<<endl;
	c = 'Z';
	cout<<"c = "<<c<<endl;
	cout<<"c = "<<(int)c<<endl;
	return 0;
output of the above program

Leave a Reply