What am I doing wrong here? Am I allocating memory to the original charPtr
or something else? Why can I read the value of charPtr
within func2
but not 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);
}