我在这里做错了什么?我是在将内存分配给原始文件charPtr
还是其他东西?为什么我可以读取charPtr
withinfunc2
而不是 in main ( charPtr
is NULL
in main) 的值?
#include <stdlib.h>
#include <stdio.h>
void func2(char *charPtr)
{
charPtr = (char *)malloc(sizeof(char));
*charPtr = 'c';
printf("func2: %c\n", *charPtr);
}
void func1(char** charDoublePointer)
{
//*charDoublePointer = (char *)malloc(sizeof(char));
func2(*charDoublePointer);
}
int main(int argsc, char* argv[])
{
char * charPtr = NULL;
func1(&charPtr);
printf("%c\n", *charPtr);
}