Basisdatentypen
In C gibt es nur vier eindeutig benannte Datentypen. char, int, float und double. char und int stellen ganze Zahlen dar, während float und double Gleitkommazahlen sind.
Für ganze Zahlen gibt es die Modifikatoren signed und unsigned, die angeben, ob die Zahl vorzeichenlos ist oder nicht.
Der Datentyp int kann weiterhin die Modifikatoren short , long und long long tragen, um die Bit-Breite des Integers zu ändern.
Werden nur Modifikatoren ohne Datentyp angegeben, so wird ein Integer als Datentyp angenommen.
Die genaue Bit-Breite von Integern ist massiv Systemabhänig, weshalb ISO-Datentypen aus <stdint.h> importiert werden sollten. Diese tragen ihre genaue Größe und alle Modifikatoren im Namen, und sind so auf allen Systemen gleich.
Mehr Informationen zu den Basistypen findet sich hier.
#include <stdio.h>
#include <stdint.h>
int main()
{
// char
char c1;
signed char c2; // equivalent to c1
unsigned char c3;
int8_t c4; // equivalent to c1 and c2
uint8_t c5; // equivalent to c3
// int
int i1;
signed int i2; // equivalent to i1
unsigned int i3;
signed i4; // equivalent to i1 and i2
unsigned i5; // equivalent to i3
int32_t i6; // equivalent to i1, i2 and i4
uint32_t i7; // equivalent to i3 and i5
// short
short s1;
short int s2; // equivalent to s1
signed short int s3; // equivalent to s1 and s2
unsigned short int s4;
unsigned short s5; // equivalent to s4
int16_t s6; // equivalent to s1, s2 and s3
uint16_t s7; // equivalent to s4 and s5
// long and long long
long l1; // equivalent to i1 or l6
long int l2; // equivalent to l1
signed long int l3; // equivalent to l1 and l2
unsigned long int l4; // equivalent to i3 or l7
unsigned long l5; // equivalent to l4
long long l6;
unsigned long long int l7; // equivalent to l6
int64_t l8; // equivalent to l1, l2, l3 and l6
uint64_t l9; // equivalent to l4, l5 and l7
// float & double
float f1;
float_t f2; // equivalent to f1 or f3
double f3;
double_t f4; // equivalent to f3 or f5
long double f5; // equivalent to f4 or extra type
// special types
size_t size;
intptr_t intptr;
uintptr_t uintptr;
ptrdiff_t ptrdiff;
return 0;
}