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

Recommended Answers

All 2 Replies

it is. passing a pointer is no different to passing anything else. Its a parameter the same as any other.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.