I have code that works, however I'm not quite understanding why. I am allocating a pointer with a string, passing that string into a function, and modifying it. I'm confused in that it seems to run fine even if the string entered is far larger than the original string. I expect it to complain about overwriting memory, especially since the original pointer was not MALLOC/CALLOCed.
void changeArray(char *(*anArray)[3]); Function Declaration
char *testArray[] = { "This is a test", "A Second Test", "A Third Test" }; Pointer declaration & init
changeArray(&testArray); Function Call
void changeArray(char *(*anArray)[3]){ char userName[200]; printf("What is your name?:\t"); scanf("%199[^\n]s", userName); *anArray[0] = userName; } The Function
printf("Your name is: %s\n", testArray[0]); Printing the result in main.
Why is testArray[0] able to accept the new string without reallocating memory for it? Even more baffling is I'm looking at the result under locals and it appears corrupted, but still prints fine.
+ [0] 0x00e2f850 "D`\x3\x1 øâ" char * I know it's weird to ask about working code, but I need to make sure I'm understanding what's happening so I can correctly implement/avoid it later.