C Cheat Sheet
by python_cheat_sheet via cheatography.com/165448/cs/39716/
Datentypen Schleifen und Verzweigungen
Typ Bytes Bereich Loops
int 2 oder 4 ±32.000 oder ±2.000.000.000 for (int i = 0; i < 4; i++) { ... }
308 for (int i = 0, j = 10; i < 5; i++, j--){ ... }
double 8 Kommazahl: 15 Stellen und ±10
while (a == 7) { ... }
char 1 ASCII Buchstaben
do { ... } while (a == 5);
int_Nt N -2N-1 bis 2N-1
If...else
uint_Nt N 0 bis 2N-1 if (n < 2) { ... }
else if (n < 4) { ... }
Operatoren
else { ... }
+,-,*,/ Plus, Minus, Mal, Geteilt Switch
% Rest (9 % 4 = 1) switch (n) {
== , != Gleich, Ungleich case 1: { ... }; break;
case 2: { ... }; break;
> , < , >= , <= Größer, Kleiner
default: { ... }; break;
&& , || , ! Und, Oder, Nicht
}
Break/Continue
Zahlen, Zeichen und Strings
break: beendet Schleife
char c ='A'; einzelnes Zeichen continue: beendet Duchlauf
char s[6] = "Hallo"; Zeichenkette/String
Escape-Sequenzen: Funktionen
\' , \", \? , \\ , \n , \t ' , " , ? , \ , neue Zeile, Tab int sum(int a, int b) {
Zahlenformate: return a + b;
}
int bin= 0b1010110 int octal = 021
void add5(int *a) {
int hex = 0x1A double exponent = 1.5e3
*a = *a + 5;
Jeder String endet intern mit \0, "Hallo" == "Hallo\0 " return;
}
Arrays
// main function
int numbers[3] = { 4, 5, 6 }; int main() {
int numbers[100] = { 0 }; Alle Elemente sind 0 return 0;
int table[3][3]; 2 Dimesionales Array }
char *colors[2] = { "blue", "yellow" }
Präprozessor
Intern sind Arrays Zeiger: a[0] == *a , a[1] == *a(a + 1)
#define MAX 100 Konstante
Zeiger #include <filename> Importiert Standard-Bibliothek
& Adressoperator #include "filename" Impotiert eigene Header-Datei
* Dereferenzierungsoperator In einer Header-Datei werden Funktionen deklariert, die in mehreren
Dateien genutzt werden.
int *pi = &i; Speichern der Adresse von i
*pi = 5; Zugriff auf i
Adresse zum Kopieren und Teilen von Daten
By python_cheat_sheet Published 6th October, 2023. Sponsored by CrosswordCheats.com
cheatography.com/python- Last updated 1st August, 2023. Learn to solve cryptic crosswords!
cheat-sheet/ Page 1 of 2. http://crosswordcheats.com
C Cheat Sheet
by python_cheat_sheet via cheatography.com/165448/cs/39716/
Speicherverwaltung Input & Output
// Datenmenge einlesen #include <stdio.h> Bibliothek für Ein-/Ausgabe
scanf("%i", &dataCount); printf("My age is %d", age); Ausgabe auf Konsole
// Speicherplatz reservieren
scanf("%d", &value) Tastatureingabe (unsafe)
int *dynData;
%d , %c , %s, %lf int, char, string, double
dynData = (int*) malloc(sizeof(int) * dataCount);
// Speicherplatz freigeben Formatangabe: %[flags][width][.precision][length]specifier
free(dynData); Details auf https://cplusplus.com/reference/cstdio
Enum Abkürzungen
typedef enum { SLOW = 5, FAST = 100 } Speed; a++ a=a+1
Speed carSpeed = SLOW; a += 2 a=a+2
// default: C1 = 1, C2 = 2 usw.
q? a1 : a2 if q a1 else a2
Strukturen
typedef struct {
int day;
char month[4];
} Date;
Date today= { 1, "Jun" }; // Anlegen einer
Instanz
today.day = 2; //Zugriff auf Elemente
Date *pToday = &today //Anlegen eines Zeigers
pToday->day = 3; // Zugriff auf Elemente
/*Alternativen mit wenig Speicherverbrauch:
union und bitfield*/
Dateibearbeitung
fopen() Öffnen einer Datei
fclose() Schließen einer Datei
fseek() Verändern der Beareitungsposition
fgetc(), fputc() Zeichenweise Lesen/Schreiben
fscanf(), fprintf() Formatiertes Lesen/Schreiben
fgets() Zeilenweise Lesen
fputs() Stringweise Scheiben
fread(), fwrite() Binäres Lesen/Schreiben (byteweise)
sscanf(), sprintf() Strings Lesen/Schreiben
Details auf https://cplusplus.com/reference/cstdio
By python_cheat_sheet Published 6th October, 2023. Sponsored by CrosswordCheats.com
cheatography.com/python- Last updated 1st August, 2023. Learn to solve cryptic crosswords!
cheat-sheet/ Page 2 of 2. http://crosswordcheats.com