| | |
Pass by pointer
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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
Actually i am not sure that...changing address is flaw...
plz comment
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
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
2. use of '&' operator inside the passing function
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.
1. use of dot or pointer operators within the receiving function
C++ Syntax (Toggle Plain Text)
void foo(int* n) { *n = 0; } void foo(int& n) { n = 0; }
C++ Syntax (Toggle Plain Text)
int main() { int n; foo(&n); foo(n); return 0; }
Otherwise, the dot and pointer operator compile down to the same identical code. Its all really just a matter of programmer preference.
![]() |
Similar Threads
- c language problm, how to pass pointer to a function (C)
- How to pass a function pointer as an argument? (C++)
- total newb - "passing arg 2 of `strcpy' makes pointer from integer without a cast" (C++)
Other Threads in the C++ Forum
- Previous Thread: I need some help for a C++ program
- Next Thread: C++ questions, How do they do it?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






