Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is unsigned char i equivalent to unsigned j?

Tags:

c

types

unsigned

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?

like image 472
msc Avatar asked Sep 06 '16 05:09

msc


1 Answers

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
like image 161
Blagovest Buyukliev Avatar answered Oct 10 '22 02:10

Blagovest Buyukliev