passing pointers in nested functions
I noticed today that a pointer declared in main, when passed to function that passes to a function, will not change regardless of what these functions do -- altho the changes in the second function affect the first function (but not main) whereas one passed to a function that changes it will. Am I off my rocker? Why is this?
Code:
int main() {
struct _node *ptr=NULL;
function1(ptr);
//ptr still NULL
}
function1(struct _node *ptr){
function2(ptr);
//ptr reflects malloc & assignment
}
function2(struct _node *ptr{
malloc and assign ptr.
}