Why char is unsigned and int is signed by default?

I’m using gcc as my c++ compiler and when I declare a variable of int datatype then it is taken as signed by default. But in case of char it is taken as unsigned.
Why is that ?
Because in xcode IDE char is taken as signed by default.


using namespace std;

int main() {
   int x;
   char y;
   cout<<INT_MIN<<" "<<INT_MAX<<endl;
   cout<<CHAR_MIN<<" "<<CHAR_MAX<<endl;

   return 0;


-2147483648 2147483647
0 255

>Solution :

char is an unsigned type on your system, because the people who implemented your system chose that it should be unsigned. This choice varies between systems, and the C++ language specifies that either is allowed. There is no "default" choice. You cannot assume one choice if you wish to write programs that work across different systems.

Note that char, signed char and unsigned char are all three distinct types regardless of whether char is signed or not. By contrast, int and signed int are two names for one and the same type.

Leave a Reply