| | |
passby pointer or reference?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
One function is pass by pointer which stores the reference, the other is just pass by a reference... are theses methods equvilent or does one method require more memory than the other?
c++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; void cubeByRef(int *num); void cubeByRef2(int &num); int main(){ int a = 2; cubeByRef(&a); cout << "cubeByRef : " << a << endl; a = 2; cubeByRef2(a); cout << "cubeByRef2: " << a << endl; return 0; } void cubeByRef(int *num){ *num = *num * *num * *num; } void cubeByRef2(int &num){ num = num * num * num; }
>> are theses methods equvilent
yes (almost). There are a couple things that can be done with pointer num that can not be done with the reference.
>> or does one method require more memory than the other?
no
yes (almost). There are a couple things that can be done with pointer num that can not be done with the reference.
>> or does one method require more memory than the other?
no
Last edited by Ancient Dragon; Oct 26th, 2007 at 9:24 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
The internal code produced by your compiler most likely is the same for both functions, so there would be no difference in memory requirements. The difference between the two functions is the c++ language requirements, compilers may implement them however it wants to.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- pointer to a refernce (C++)
- Pass by pointer (C++)
- pointer (C)
Other Threads in the C++ Forum
- Previous Thread: array and structures.
- Next Thread: learning WIN32 GDI
| 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 delete deploy desktop directshow dll download dynamic dynamiccharacterarray 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 output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






