Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between unsigned short int and unsigned short

Tags:

c

unsigned

Is there a difference between unsigned short int and a unsigned short decleration in c and if so, what is it please ? I tried looking online, but couldn't find anything worthwhile.

unsigned short int x1;
unsigned short x2;

Lastly, if there is a difference, how can I cast them to each other respectively please?

like image 744
Goaler444 Avatar asked Apr 29 '13 16:04

Goaler444


People also ask

What is the difference between short and unsigned short?

The standard mandates that the range is (as for short ) at least -32767 to 32767 , so an int must be at least 16 bits wide. For unsigned ( int and short ), the range must be at least 0 to 65535 , so that too must be at least 16 bits wide.

What is an unsigned short int?

It is the smallest (16 bit) integer data type in C++. Some properties of the unsigned short int data type are: Being an unsigned data type, it can store only positive values. Takes a size of 16 bits.

What is the difference between unsigned and unsigned int?

There is no difference. unsigned and unsigned int are both synonyms for the same type (the unsigned version of the int type).

What are the differences between an unsigned short int and a long int?

There's no difference. It's an unsigned short , actually the int keyword is optional for short or long declarations. The unsigned keyword may applied to all of these type declarations, and makes them just unsigned .


2 Answers

From C11 [PDF] (irrelevant parts omitted) (emphasis mine):

6.7.2.2:

At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.

  • ...
  • short, signed short, short int, or signed short int
  • unsigned short, or unsigned short int
  • ...

6.7.2.5:

Each of the comma-separated multisets designates the same type ...

like image 96
Shahbaz Avatar answered Oct 07 '22 00:10

Shahbaz


Just using short is a short-hand (no pun intended) way of writing short int. Just a long is a short-hand for long int.

like image 42
Some programmer dude Avatar answered Oct 06 '22 22:10

Some programmer dude