Variables

  • varType varName = value

Types:

DatentypWertebereich (min.)FormatzeichenGröße (Bits)
signed char-128
bis +127
%hhd (für dezimal), %c (für Zeichen)8
unsigned char0
bis 255
%hhu8
short-32.768
bis +32.767
%hd oder %hi16
unsigned short0
bis 65.535
%hu16
int-32.768
bis +32.767 (auf einigen Systemen -2.147.483.648 bis +2.147.483.647)
%d oder %i16/32 (plattformabhängig)
unsigned int0
bis 65.535 (auf einigen Systemen bis 4.294.967.295)
%u16/32 (plattformabhängig)
long-2.147.483.648
bis +2.147.483.647
%ld oder %li32
unsigned long0
bis 4.294.967.295
%lu32
long long (seit C99)-9.223.372.036.854.775.808
bis +9.223.372.036.854.775.807
%lld oder %lli64
unsigned long long0
bis 18.446.744.073.709.551.615
%llu64
bool (seit C99)0 und 1%u1 (in der Praxis oft 8)
float1.2E-38
bis 3.4E+38
%f32
double2.3E-308
bis 1.7E+308
%f (%lf für scanf)64
long double3.4E-4932
bis 1.1E+4932
%Lf80/128 (plattformabhängig)

signed vs. unsigned

  • the variable is signed
  • the key difference is the value range same amount of values, but unsigned vars include negative values as well. Because of that the positive range of a signed variable is twice as much compared to unsigned variables

constants are unchangeable vars

const int num = 5;
//the var num cant be changed in the following program