下标到指针之间和转换以下的程序做了什么。
#include
int main()
{
int a[3][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
int i = 0;
int j = 0;
for(i = 0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%d\n", *(*(a+i)+j));
}
}
}
打印了数组中的每个元素:
指向指针的指针
#include
int main()
{
int a = 1;
int* p = NULL;
int** pp = NULL;
pp = &p;
*pp = &a;// ==> p = &a;
printf("%d", **pp);
return 0;
}
使用实例:重置动态空间大小(类似于在函数中修改入参)
#include
int reset(char**p, int size, int new_size)
{
int ret = 1;
int i = 0;
int len = 0;
char* pt = NULL;
char* tmp = NULL;
char* pp = *p;
if( (p != NULL) && (new_size > 0))
{
pt = (char*)malloc(new_size);
tmp = pt;
len = (size < new_size) ? size : new_size;
for( i=0; i
{
*tmp++ = *pp++;
}
free(*p);
*p = pt;
}
return ret;
}
int main()
{
char* p = (char*)malloc(5);
printf("%0X\n", p);
if( reset(&p, 5, 3) )
{
printf("%0X\n", p);
}
return 0;