Types of integers in C, characters and casting

Introduction

Integer types in C

Standard (signed) integers

Following are equivalent.

Signed means includes +ve and -ve numbers.

These are at least 16-bit (ie could be 32, 64, 16, or something else - up to the implementaion)

In 16 bit this goes between -32,767 and 32,767.

int a = 1;
signed int a = 1;
signed a = 1;

Unsigned integers

If these are 16-bit these are between \(0\) and \(65,535\).

unsigned int a = 1;
unsigned a = 1;

Short integers

These are at least 16 bit, and equal or lesser than standard integers in their bits.

short int a = 1;
signed short int a = 1;
signed short a = 1;
short a = 1;

Unsigned versions.

unsigned short int a = 1;
unsigned short a = 1;

32-bit

Guaranteed to be at least as big as int, and at least 32 bit.

long int a = 1;
signed long int a = 1;
signed long a = 1;
long a = 1;

Unsigned versions:

unsigned long int a = 1;
unsigned long a = 1;

64-bit

Guaranteed to be at least as big as long, and at least 64 bit.

long long int a = 1;
signed long long int a = 1;
signed long long a = 1;
long long a = 1;

Unsigned versions:

unsigned long long int a = 1;
unsigned long long a = 1;

char

At least 8 bit.

char can be unsigned or signed.

char a = 1;

If signed is between -127 and 128 (if 8 bit)

signed char a = 1;

If unsigned is between 0 and 255 (if 8 bit)

unsigned char a = 1;

Using American Standard Code for Information Interchange (ASCII)

char a = "a";

Casting

unsigned short int a = 1;
unsigned long long b = (long long) a;