读书人

更改二级指针所指内容?解决方案

发布时间: 2012-02-14 19:19:19 作者: rapoo

更改二级指针所指内容??
int *pi = NULL;
int **ppi = NULL;

pi = (int*)malloc(4);
memset(pi,0,4);
ppi = (int**)malloc(4);
memset(ppi,(int)pi,4); //所指内容置为pi值
**ppi = 10; //!!!挂掉

////////////////////////////
怎么修改可以赋给**ppi值

[解决办法]
void *memset( void *dest, int c, size_t count );

Return Value

memset returns the value of dest.

Parameters

dest

Pointer to destination

c

Character to set

count

Number of characters

Remarks

The memset function sets the first count bytes of dest to the character c.

故在此函数仅仅取了pi中的一个字节大小的内容,然后重复了4次,故指向不对了

读书人网 >C语言

热点推荐