动态内存分配
#include <stdio.h>
#include <malloc.h>
void main(void)
{
int * p = (int *)malloc(sizeof(int)*4);
int i = 0;
int j = 1;
for (i = 0; i<4; ++i)
{
p[i] = j;
++j;
}
printf("%d\n", p);
printf("%#x\n", p);
printf("%d\n", p+1);
printf("%#x\n", p+1);
printf("%d\n", p+2);
printf("%#x\n", p+2);
printf("%d\n", p+3);
printf("%#x\n", p+3);
printf("\n");
printf("%d\n", *p);
printf("%d\n", *(p+1));
printf("%d\n", *(p+2));
printf("%d\n", *(p+3));
printf("\n");
printf("%d\n", p[0]);
printf("%d\n", p[1]);
printf("%d\n", p[2]);
printf("%d\n", p[3]);
return;
}
/****************************
执行结果
———————————
9449096
0x902e88
9449100
0x902e8c
9449104
0x902e90
9449108
0x902e94
1
2
3
4
1
2
3
4
———————————
****************************/