20 mars 20241 min de lecture
Cheat sheet — Langage C (syntaxe essentielle)
Révision rapide du C : structure d'un programme, types, entrées/sorties (printf/scanf), conditions et boucles, pointeurs, tableaux, chaînes, structures, fichiers, allocation dynamique, manipulation de bits, Makefile et compilation.
intro#langage-c#programmation#reverse-engineering#cheatsheet
Mis à jour le 21 sept. 2026
Structure & E/S
#include <stdio.h>
int main(void) {
int a;
scanf("%d", &a); // entrée
printf("Valeur : %d\n", a); // sortie
return 0;
}
Spécificateurs : %d (int), %c (char), %f (float), %lf (double),
%s (chaîne). Échappements : \n, \t, \\, \'.
Conditions & boucles
if (cond) { } else { }
switch (x) { case 1: /*...*/ break; default: /*...*/ }
while (cond) { }
for (int i = 0; i < n; i++) { }
Pointeurs
int x = 12, *ptr;
ptr = &x; // adresse de x
printf("%d", *ptr); // déréférencement → 12
Tableaux & chaînes
int t[10];
char s[50]; // chaîne = tableau de char terminé par '\0'
Fonctions string : strlen, strcpy, strcat, strcmp (clé en reverse pour
les comparaisons de mot de passe), strrev.
Structures
typedef struct {
char nom[50];
int age;
} Personne;
Fichiers
FILE *fp = fopen("f.txt", "r"); // "r" lecture, "w" écriture
fscanf(fp, "%s", buf);
fprintf(fp, "%s", "texte");
fclose(fp);
Allocation dynamique
ptr = malloc(taille); // non initialisée
ptr = calloc(n, taille); // initialisée à 0
ptr = realloc(ptr, nouvelle); // redimensionner
free(ptr); // libérer
Manipulation de bits
| Opérateur | Rôle |
|---|---|
& | ^ ~ |
AND, OR, XOR, NOT |
<< >> |
décalage gauche / droite |
unsigned int b = 5 << 1; // 00000101 → 00001010
Compilation & debug
programme: main.o utils.o
gcc -o programme main.o utils.o
clean:
rm *.o programme
gcc -Wall -o programme programme.c
gdb ./programme
Voir aussi la cheat sheet reverse GDB & assembleur.