Search code examples
ctypesunsigned

Is unsigned char i equivalent to unsigned j?


In following program I used unsigned keyword.

#include <stdio.h>

int main()
{
        unsigned char i = 'A';
        unsigned j = 'B';
        printf(" i = %c j = %c", i, j);
}

Output:

 i = A j = B

Is unsigned char i equivalent to unsigned j?


Solution

  • Is unsigned char i equivalent to unsigned j?

    No, when the type specifier is omitted and any of the signed, unsigned, short or long specifiers are used, int is assumed.

    This means that the following declarations are equivalent:

    long a;
    long int a;
    
    unsigned short b;
    unsigned short int b;
    

    The issue with the signedness of char is that when signed or unsigned is omitted, the signedness is up to the implementation:

    char x; // signedness depends on the implementation
    unsigned char y; // definitely unsigned
    signed char z; // definitely signed