Pense-bête

Transcription

Pense-bête
Pense-bête du langage C
Intégralement piraté de : H. Garreta, « C : Langage, bibliothèque, applications », InterEditions 1992
1. Opérateurs
Priorité
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
opérateurs
()
!
*bin
+
<<
<
==
&bin
^
|
&&
||
? :
=
,
[]
~
/
-bin
>>
<=
!=
.
++
%
->
--
>
>=
*=
/=
%=
-un
*un
&un
(type)
+=
-=
<<=
>>=
sens de l’associativité
→
sizeof
←
→
→
→
→
→
→
→
→
→
→
←
&=
^=
|=
←
→
2. Instructions
instruction
→ instruction-bloc
→ instruction-expression
→ instruction-goto
→ instruction-if
→ instruction-while
→ instruction-do
→ instruction-for
→ instruction-break
→ instruction-continue
→ instruction-switch
→ instruction-return
→ instruction-vide
→ identificateur : instruction
instruction-bloc
→{
déclaration … déclaration
instruction … instruction
instruction-while
→ while ( expression ) instruction
instruction-do
→ do instruction while ( expression );
instruction-for
→ for ( expressionopt ; expressionopt ;
expressionopt ) instruction
instruction-break
→ break;
instruction-continue
→ continue;
instruction-switch
→ switch ( expression )
{ instruct-ou-case … instruct-ou-case }
}
instruction-expression
→ expression ;
instruction-goto
→ goto identificateur ;
instruction-if
→ if ( expression ) instruction else instruction
→ if ( expression ) instruction
instruct-ou-case
→ case expression-constante : instructionopt
→ default: instruction
→ instruction
instruction-return
→ return expressionopt ;
instruction-vide
→;
3. Quelques fonctions (bibliothèque ANSI)
#include <stdio.h>
FILE *fopen(char *nom, char *mode);
int fclose(FILE *flot);
int fgetc(FILE *flot);
int getc(FILE *flot);
int getchar(void);
char *fgets(char *s, int n, FILE *flot);
char *gets(char *s);
int fputc(int caractere, FILE *flot);
int putc(int caractere, FILE *flot);
int putchar(int caractere);
int fputs(char *s, FILE *flot);
int puts(char *s);
int ungetc(int c, FILE *flot);
int printf(char *format, ...);
int fprintf(FILE *flot, char *format, ...);
int sprintf(char *destination, char *format, ...);
int scanf(char *format, ...);
int fscanf(FILE *flot, char *format, ...);
int sscanf(char *source, char *format, ...);
size_t fread(void *destination,
size_t taille, size_t nombre, FILE *flot);
size_t fwrite(void *source,
size_t taille, size_t nombre, FILE *flot);
int fseek(FILE *flot, long deplacement, int origine);
int fflush(FILE *flot);
#include <stdlib.h>
int atoi(char *s);
long atol(char *s);
double atof(char *s);
int rand(void);
void srand(unsigned int semence);
void *malloc(size_t taille);
void *calloc(size_t nombre, size_t taille);
void *realloc(void *ptr, size_t taille);
void free(void *adresse);
void exit(int code);
int system(char *commande);
char *getenv(char *nom);
int abs(int x);
long labs(long x);
ouverture d’un fichier
fermeture d’un fichier
lecture d’un caractère
"
"
"
"
lecture d’une chaîne
"
"
écriture d’un caractère
"
"
"
"
écriture d’une chaîne
"
"
« délecture » d’un caractère
écriture avec format
"
"
"
"
lecture avec format
"
"
"
"
lecture « en vrac »
écriture « en vrac »
positionnement
vidange des tampons
conversion chaine → nombre
"
"
"
"
génération de nombres aléatoires
allocation de mémoire
"
"
réallocation de mémoire
restitution de mémoire
abandon d’un programme
exécution d’une commande du système
valeur d’une variable du shell
valeur absolue d’un entier
#include <string.h>
size_t strlen(char *s);
char *strcpy(char *destin, char *source);
char *strcat(char *destin, char *source);
int strcmp(char *a, char *b);
longueur d’une chaîne
copie de chaîne
concaténation de chaînes
comparaison de chaînes
#include <math.h>
double fabs(double x);
double sqrt(double x);
double sin(double x), cos(double x), tan(double x);
double asin(double x), acos(double x), atan(double x);
double atan2(double y, double x);
double exp(double x), log(double x);
double log10(double x), pow(double x, double y);
valeur absolue d’un flottant
racine carrée
trigonométrie
"
"
"
"
autres fonctions transcendantes
"
"
#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