Let
f1 and f2 are two user defined functions.
main(){
int *p;
f1(&p)
}
f1(**p){
f2(&p);//If I've to pass the pointer by reference again in another function, will I've to do something like this?
}
f2(***p){
**p = NULL;
}
Let
f1 and f2 are two user defined functions.
main(){
int *p;
f1(&p)
}
f1(**p){
f2(&p);//If I've to pass the pointer by reference again in another function, will I've to do something like this?
}
f2(***p){
**p = NULL;
}
I got that I don't need to use *** in order to pass by reference again. But can you tell me why in the definition of f1 (in your code) p's address has not been passed and still it's passed by reference?
In order to pass a pointer by reference we must have to pass its address in the arguments of a function but in your case, I can't understand how it's passed by reference (though I'm sure that it's passed by reference).
But can you tell me why in the definition of f1 (in your code) p's address has not been passed and still it's passed by reference?
The entire point of using another level of indirection is so that you can access the original object. If you already have that level of indirection in place, there's no need for another. In other words, if the object you have is already a pointer to the object you want, you don't need to pass any addresses.
On a side note, what you're doing is not pass by reference, it's passing a pointer to simulate the effect of pass by reference.
Thanks a lot.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.