In dieser Lektion werden die Datentypen, Variablen und deren Eigenschaften in C auf fortgeschrittenem Niveau behandelt. Ziel ist, Speicher, Wertebereiche und Typumwandlungen zu verstehen.
char – einzelne Zeichen, typischerweise 1 Byteint – ganze Zahlen, typischerweise 4 Bytesfloat – Gleitkommazahlen, einfache Genauigkeit, 4 Bytesdouble – Gleitkommazahlen, doppelte Genauigkeit, 8 Bytes_Bool – Wahrheitswerte, 1 Byteint alter = 21;
char initial = 'A';
float temperatur = 36.6f;
double pi = 3.14159265359;
_Bool aktiv = 1;
signed, unsignedshort, longunsigned int positiveZahl = 300;
long int grosseZahl = 1000000000;
short int kleineZahl = -100;
const schützt Werte vor unbeabsichtigter Änderung.
const int MAX_VERBRAUCH = 100;
const double G = 9.81;
42, 0x2A (hexadezimal), 052 (oktal)3.14, 2.718f'A', '\n'"Hallo Welt"0 (false), 1 (true)Typ Name [= Initialwert];
int a; // Deklaration
a = 5; // Zuweisung
double b = 2.71; // Deklaration + Initialisierung
int globalVar = 10; // global
void test(void) {
int lokal = 5; // lokal
static int counter = 0; // statisch
counter++;
}
int a = 5;
double b = 2.5;
double sum = a + b; // implizit: a wird zu double
int c = (int) b; // explizit: cast zu int
printf("%f %d\n", sum, c);
const