0

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;
}

Edited by MRehanQadri

3
Contributors
4
Replies
28
Views
5 Years
Discussion Span
Last Post by MRehanQadri
0

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).

Edited by MRehanQadri

2

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.