If I've declared a pointer p
as int *p
; in main module, I can change the address contained by p
by assigning p = &a;
where a
is another integer variable already declared.
I now want to change the address by using a function as:
void change_adrs(int*q)
{
int *newad;
q = newad;
}
If I call this function from main module
int main()
{
int *p;
int a = 0;
p = &a; // this changes the address contained by pointer p
printf("The address is %u\n", p);
change_adrs(p);
printf("The address is %u\n", p); // but this doesn't change the address
return 0;
}
the address content is unchanged. What's wrong with using a function for same task?