12.07.2015 Views

Langage Ca - Pages de Michel Deloizy - Free

Langage Ca - Pages de Michel Deloizy - Free

Langage Ca - Pages de Michel Deloizy - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

pgm.exe –x3toto.dat titi.out• argc = 4• argv[0]="[0]="pgm.exe"" (avec le chemin d'accès complet)• argv[1]="[1]="-x3"• argv[2]="[2]="toto.dat"• argv[3]="[3]="titi.out"132 Ponteurs <strong>de</strong> fonctionsNom <strong>de</strong> fonction → adresse <strong>de</strong> la fonction→ Pointeur <strong>de</strong> fonctionPeut être utilisé pour in<strong>de</strong>xer une fonction parmi plusieurs.Exemple :void TriBulle(intint t[ ], int nb);void TriInsertion(intint t[ ], int nb);void (*fctTrifctTri)( )(intt[ ], int nb);…int tab[ ] = {1, 4, 0, -1, 2};fctTri = TriBulle;fctTri(tab,(tab,sizeof(tab)/sizeof(*tab));fctTri = TriInsertion;fctTri(tab,(tab,sizeof(tab)/sizeof(*tab));133 Allocation dynamique <strong>de</strong> mémoire→Quand un espace mémoire m moire est requis, <strong>de</strong> taille inconnue lors <strong>de</strong> la conception duprogramme→Pour optimiser l'utilisation <strong>de</strong> la mémoiremmoire→Deman<strong>de</strong> <strong>de</strong> mémoire m moire à l'environnementFonctions :134 Exemple• void * malloc(size_tsz);Renvoie un pointeur sur la zone allouéeou NULL si pas d'espace disponible• void free(void* ptr);Libère l'espace mémoire m moire attribué par mallocint nb, , *tab;printf("Nombre <strong>de</strong> valeurs à acquérir :");scanf("%d",&("%d",&nb);tab = malloc(nbnb*sizeof(*tab));if(tab!=NULL) {int i;for(i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!