Hi,
I'm trying to pass a variable to testVars(), have testVars() change the variable, and then make that variable available to main().
Passing the variable from main() to testVars() is working--getting it back to main() is not.
The expected result is that the program will print the following two lines:Code:#include <stdio.h> #include <stdlib.h> char testVars(char *a, char *b); main() { char * testChar = "We just passed"; char * testCharTwo = "a main() variable!"; testVars(testChar, testCharTwo); printf("%s %s - Back to main()!\n", testChar, testCharTwo); return 0; } char testVars(char *a, char *b) { b = "a variable!"; printf("%s %s\n", a, b); }
We just passed a variable!
We just passed a variable! - Back to main()!
But what I'm getting is:
We just passed a variable!
We just passed a main() variable! - Back to main()!
I'm new to C and am still in the early stages of learning it, but it's my understanding that if I pass a pointer variable from main(), in my case, to testVars() that testVars() is actually working with the dereferenced location of testCharTwo (since this is the only one I wish to change in testVars()) and any modifications it makes to testCharTwo should be immediately available to main().
Am I missing something here? Or is my understanding of this not correct?
~ Tom