0

Why in C++ passing a pointer is not termed as a parameter passing technique.....Is it because it has a flaw of some kind i.e. address is not reflected back/we can change the address in called function..is that so...if that's the reason....then we can pass it as const pointer as a remedy.....

Actually i am not sure that...changing address is flaw...

plz comment

3
Contributors
2
Replies
4
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

It is indeed a parameter passing technique -- there are only two ways to pass something, by value and by reference. Pass by reference can be done in one of two ways -- a pointer (C) or reference operator (C++). The three differences I can think of
1. use of dot or pointer operators within the receiving function

void foo(int* n)
{
	*n = 0;
}

void foo(int& n)
{
	n = 0;
}

2. use of '&' operator inside the passing function

int main()
{
	int n;
	foo(&n);
	foo(n);
	return 0;
}

3. They can be overloaded functions as shown in the examples above.

Otherwise, the dot and pointer operator compile down to the same identical code. Its all really just a matter of programmer preference.

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.