I am having some difficulty in understanding pointers when passed to functions. When I pass a pointer to a function and assign some dynamic memory to its argument in the other function, should that dynamic memory be reflected in the invoking block?
I have some code below. As you can see from executing it, the string and memory assigned in the function is not reflected in main. Why is this? If the value of testThis is an address and is being assigned to ttArg, shouldn't testThis and ttArg point to the same memory location?
void testPointer(char *);
char * testThis;
printf("testThis in main is %s\n", testThis);
} /* end main */
/* begint the testPointer */
void testPointer(char * ttArg)
ttArg = (char *)malloc(10);
strncpy(ttArg, "hello", 6);
printf("ttArg in testPointer() is %s\n", ttArg);
} /* end testPointer */