| | |
parameters
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
Originally Posted by vudatalark
how many ways can you pass parameters to a function in c++
- By value.
- By pointer.
- By reference.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
>1. By value.
Okay.
>2. By pointer.
Pointers are passed by value, let's not add to the massive amount of confusion surrounding pointers, k?
>3. By reference.
Okay.
You can also pass values and types to a function by way of templates. But the original question is rather vague, so it might be best to wait for clarification before answering definitively.
Okay.
>2. By pointer.
Pointers are passed by value, let's not add to the massive amount of confusion surrounding pointers, k?

>3. By reference.
Okay.
You can also pass values and types to a function by way of templates. But the original question is rather vague, so it might be best to wait for clarification before answering definitively.
•
•
•
•
Originally Posted by Narue
>2. By pointer.
Pointers are passed by value
•
•
•
•
Originally Posted by Narue
let's not add to the massive amount of confusion surrounding pointers, k?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Allow me to make things more confusing....
Narue, when you say pointers are passed by value, I don't understand what you mean.
void foo ( int byVal, int *byPointer, int &byRef );
the second integer parameter is passed by pointer.
I'm guessing you are referring to passing a pointer by value in some specific case? But you can replace <int> above with anything including pointers, and in that case you could have something like this:
void Bar( char* s1, char** s2, char*& s3 );
only in the first case is the pointer passed by value in the sense you mean, I'd guess? But it depends on your point of view: It could be a pointer to a char or it could be a char pointer you are passing by value!
I'm not disagreeing with you, but I don't see how that modifies Dave's original list of by value, by pointer, or by reference.
Narue, when you say pointers are passed by value, I don't understand what you mean.
void foo ( int byVal, int *byPointer, int &byRef );
the second integer parameter is passed by pointer.
I'm guessing you are referring to passing a pointer by value in some specific case? But you can replace <int> above with anything including pointers, and in that case you could have something like this:
void Bar( char* s1, char** s2, char*& s3 );
only in the first case is the pointer passed by value in the sense you mean, I'd guess? But it depends on your point of view: It could be a pointer to a char or it could be a char pointer you are passing by value!
I'm not disagreeing with you, but I don't see how that modifies Dave's original list of by value, by pointer, or by reference.
>Narue, when you say pointers are passed by value, I don't understand what you mean.
The pointer is passed by value, even if you can get to the original object by dereferencing it. This is a poor man's call-by-reference because you aren't actually calling by reference, just passing an address so that you can fake the behavior of call-by-reference.
I admit that it's a subtle difference, but trust me that it's an important one to understand completely.
The pointer is passed by value, even if you can get to the original object by dereferencing it. This is a poor man's call-by-reference because you aren't actually calling by reference, just passing an address so that you can fake the behavior of call-by-reference.
I admit that it's a subtle difference, but trust me that it's an important one to understand completely.
Ah, and here all this time I've been thinking of pass by reference as the same as pass by pointer, but with the compiler hiding the pointer syntax from you. :0)
Yeah, bottom line is that the stack only holds (on Windows) 32-bit values, and the compiler can emit an int, a padded char or short (padded to 32 bits), or an address of something. Or, I suppose, two 32 bit values for 'double' and 64-bit values.
Yeah, bottom line is that the stack only holds (on Windows) 32-bit values, and the compiler can emit an int, a padded char or short (padded to 32 bits), or an address of something. Or, I suppose, two 32 bit values for 'double' and 64-bit values.
![]() |
Similar Threads
- NTVDM Input Parameters for running QBASIC (Visual Basic 4 / 5 / 6)
- Will somebody please explain value parameters to me!!! (C)
- Windows Main and Command Line Parameters (C)
- variable function parameters functionname(int a, ...) (C)
- passing arrays,reference and value parameters (C)
- DOS C++, pulling boot order and hard drive parameters, (C++)
Other Threads in the C++ Forum
- Previous Thread: Format Specifier problem C++
- Next Thread: Need direction on how start this program
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






