Char / Character Data Type
How is "char" datatype used in C++?.
Explanation
The
"char" data type is used to represent character or small integers. Mostly this datatype is used for ASCII codes. The signed range of the char datatype is between -128 to 127 and the unsigned range is between 0 to 255.
Example :
#include <iostream.h> using namespace std; void main() { char c = 'A'; cout << c << '\n'; cout << "Bytes used by char is:" << sizeof(c); }
|
Result:
A
Bytes used by char is:1
In the above example a character "A" is declared using the char data type. Using the sizeof() function the number of bytes occupied by the datatype is also retreived.