1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("sizeof(int) = %d \n",sizeof(int));
printf("sizeof(int*)= %d \n",sizeof(int*));
printf("sizeof(int**)= %d \n",sizeof(int**));
int **ppint=(int**)malloc(2*sizeof(int*));
if(ppint!=NULL){
printf("*ppint = %d\n",(*ppint));
printf("ppint[0] = %d\n",ppint[0]);
printf(" allocation memoire à ppint[0]\n");
(*ppint)=(int*)malloc(sizeof(int));
printf("ppint = %d\n",(ppint));
printf("ppint(int) = %d\n",(ppint)+1);
printf("*ppint = %d\n",(*ppint));
printf("ppint[0] = %d\n",ppint[0]);
printf(" allocation memoire à ppint[1]\n");
(*(ppint + 1))=(int*)malloc(sizeof(int));// et non ((*ppint)+sizeof(int*))=malloc(sizeof(int));
printf("ppint + 1 = %d\n",(ppint + 1));
printf("*ppint + 1 = %d\n",(*ppint + 1));
printf("*(ppint + 1) = %d\n",*(ppint + 1));
printf("ppint[1] = %d\n",ppint[1]);
printf("&ppint[1] = %d\n",&ppint[1]);
printf(" test de cast\n");
unsigned int adr=(int)ppint;//cast du pointeur en entier non signé
int** pptmp;
printf("(adr + 4) = %d\n",adr + 4);
pptmp=(int**)(adr+4);
printf("*(pptmp) (pptmp contient la valeur de adr+4 avec un cast)=%d\n",*(pptmp));
free(*ppint);free(*(ppint+1));free(ppint);
}
return(0);
} |
Partager