Vous êtes sur la page 1sur 2

Pense-bête du langage C

Intégralement piraté de : H. Garreta, « C : Langage, bibliothèque, applications », InterEditions 1992

1. Opérateurs
Priorité opérateurs sens de l’associativité
15 () [] . -> →
14 ! ~ ++ -- -un *un &un (type) sizeof ←
13 *bin / % →
12 + -bin →
11 << >> →
10 < <= > >= →
9 == != →
8 &bin →
7 ^ →
6 | →
5 && →
4 || →
3 ? : ←
2 = *= /= %= += -= <<= >>= &= ^= |= ←
1 , →

2. Instructions
instruction instruction-while
→ instruction-bloc → while ( expression ) instruction
→ instruction-expression
instruction-do
→ instruction-goto
→ do instruction while ( expression );
→ instruction-if
→ instruction-while instruction-for
→ instruction-do → for ( expressionopt ; expressionopt ;
→ instruction-for expressionopt ) instruction
→ instruction-break instruction-break
→ instruction-continue → break;
→ instruction-switch
instruction-continue
→ instruction-return
→ continue;
→ instruction-vide
→ identificateur : instruction instruction-switch
→ switch ( expression )
instruction-bloc
{ instruct-ou-case … instruct-ou-case }
→{ déclaration … déclaration
instruction … instruction } instruct-ou-case
→ case expression-constante : instructionopt
instruction-expression
→ default: instruction
→ expression ;
→ instruction
instruction-goto
instruction-return
→ goto identificateur ;
→ return expressionopt ;
instruction-if
instruction-vide
→ if ( expression ) instruction else instruction
→;
→ if ( expression ) instruction
3. Quelques fonctions (bibliothèque ANSI)
#include <stdio.h>
FILE *fopen(char *nom, char *mode); ouverture d’un fichier
int fclose(FILE *flot); fermeture d’un fichier
int fgetc(FILE *flot); lecture d’un caractère
int getc(FILE *flot); " "
int getchar(void); " "
char *fgets(char *s, int n, FILE *flot); lecture d’une chaîne
char *gets(char *s); " "
int fputc(int caractere, FILE *flot); écriture d’un caractère
int putc(int caractere, FILE *flot); " "
int putchar(int caractere); " "
int fputs(char *s, FILE *flot); écriture d’une chaîne
int puts(char *s); " "
int ungetc(int c, FILE *flot); « délecture » d’un caractère
int printf(char *format, ...); écriture avec format
int fprintf(FILE *flot, char *format, ...); " "
int sprintf(char *destination, char *format, ...); " "
int scanf(char *format, ...); lecture avec format
int fscanf(FILE *flot, char *format, ...); " "
int sscanf(char *source, char *format, ...); " "
size_t fread(void *destination, lecture « en vrac »
size_t taille, size_t nombre, FILE *flot);
size_t fwrite(void *source, écriture « en vrac »
size_t taille, size_t nombre, FILE *flot);
int fseek(FILE *flot, long deplacement, int origine); positionnement
int fflush(FILE *flot); vidange des tampons
#include <stdlib.h>
int atoi(char *s); conversion chaine → nombre
long atol(char *s); " "
double atof(char *s); " "
int rand(void); génération de nombres aléatoires
void srand(unsigned int semence);
void *malloc(size_t taille); allocation de mémoire
void *calloc(size_t nombre, size_t taille); " "
void *realloc(void *ptr, size_t taille); réallocation de mémoire
void free(void *adresse); restitution de mémoire
void exit(int code); abandon d’un programme
int system(char *commande); exécution d’une commande du système
char *getenv(char *nom); valeur d’une variable du shell
int abs(int x); valeur absolue d’un entier
long labs(long x);
#include <string.h>
size_t strlen(char *s); longueur d’une chaîne
char *strcpy(char *destin, char *source); copie de chaîne
char *strcat(char *destin, char *source); concaténation de chaînes
int strcmp(char *a, char *b); comparaison de chaînes
#include <math.h>
double fabs(double x); valeur absolue d’un flottant
double sqrt(double x); racine carrée
double sin(double x), cos(double x), tan(double x); trigonométrie
double asin(double x), acos(double x), atan(double x); " "
double atan2(double y, double x); " "
double exp(double x), log(double x); autres fonctions transcendantes
double log10(double x), pow(double x, double y); " "
#include <assert.h>
void assert(int expression); vérification d’une condition
#include <signal.h>
void (*signal(int signum, void (*handler)(int)))(int); interception d’un signal
#include <setjmp.h>
int setjmp(jmp_buf contexte);
void longjmp(jmp_buf contexte, int code); branchement hors-fonction

Vous aimerez peut-être aussi