how many ways can you pass parameters to a function in c++
Do you mean this?By value.
By pointer.
By reference.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
>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.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>2. By pointer.
Pointers are passed by value
2. Using a pointer to simulate pass by reference.let's not add to the massive amount of confusion surrounding pointers, k?Too late(?)
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
>2. Using a pointer to simulate pass by reference.
Much better. ;)
>Too late(?)
Better late than never.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>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. :)
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401