References are preferable, even const references, if you need immutable object. Passing by pointer is needed if argument may be null... Answer from imironchik on reddit.com
🌐
Reddit
reddit.com › r/cpp_questions › passing by reference vs passing by pointer
r/cpp_questions on Reddit: Passing by reference vs passing by pointer
August 13, 2023 -

I am aware that both of the following are acceptable.

...header file...
class BigClass{
};
....outside....
BigClass BigObject;
void foo(BigClass& object); // a
void foo(BigClass* objectptr); // b

Purely from a typing point of view, would not `a` be preferred? If I have to refer to a member function inside foo via option a, it is simply `object.function();` as opposed to the more cumbersome option b which yields `objectptr->function();`

I say cumbersome because typing `-` followed by `>` usually requires me to look at the keyboard and then 3 key presses (one of them being a shift key) while with a `.` it is much quicker.

Do professional programmers use some sort of a snippet expansion which makes the `->` flow much quicker?

🌐
Hackr
hackr.io › home › articles › programming
Passing by Reference vs Passing by Pointer in C++
January 30, 2025 - Pass by reference (C++ only) Pass-by-reference means to pass the reference of an argument in the calling function to the corresponding
Discussions

Are there benefits of passing by pointer over passing by reference in C++? - Stack Overflow
What are the benefits of passing by pointer over passing by reference in C++? Lately, I have seen a number of examples that chose passing function arguments by pointers instead of passing by refer... More on stackoverflow.com
🌐 stackoverflow.com
When to use pointers and references? - C++ Forum
Passing/variables by pointer is faster because it does not make a copy. It also allows the pointer variable to be changed at the root of the function. Passing/variables by reference is similar to pointers but they cannot be reassigned and are aliases instead of memory addresses. More on cplusplus.com
🌐 cplusplus.com
August 30, 2019
c++ - Pass by reference vs pass by pointer? - Stack Overflow
Possible Duplicate: When to pass by reference and when to pass by pointer in C++? What is the difference between passing by reference and passing the value by a pointer? More on stackoverflow.com
🌐 stackoverflow.com
Pass by reference Vs Pointer
I’m new to this, and it might have been answered before, but I still can’t grasp the distinction between passing by pointer and passing by reference. In Unreal Engine’s source code, they often use pointers, but occasionally use references. Both can be interchanged and still function and ... More on forums.unrealengine.com
🌐 forums.unrealengine.com
1
0
October 19, 2023
People also ask

What is the primary difference between pass by reference and pass by pointer?
The primary difference between pass by reference and pass by pointer is that pointer can be null and reassigned, but references cannot.
🌐
techgeekbuzz.com
techgeekbuzz.com › blog › pass-by-reference-vs-pass-by-pointer-in-cpp
Pass by Reference vs Pass by Pointer in C++ [Differences]
When should you use pass by pointer?
Use pass by pointer when you want to actually modify the pointer and not the object the pointer points to.
🌐
techgeekbuzz.com
techgeekbuzz.com › blog › pass-by-reference-vs-pass-by-pointer-in-cpp
Pass by Reference vs Pass by Pointer in C++ [Differences]
When should you use pass by reference?
You should use pass by reference when you wish to modify the local variables of the caller function, have large-sized arguments, and want to make a function polymorphic.
🌐
techgeekbuzz.com
techgeekbuzz.com › blog › pass-by-reference-vs-pass-by-pointer-in-cpp
Pass by Reference vs Pass by Pointer in C++ [Differences]
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › passing-by-pointer-vs-passing-by-reference-in-cpp
Passing By Pointer vs Passing By Reference in C++ - GeeksforGeeks
January 11, 2025 - // C++ program to swap two numbers using // pass by pointer #include <iostream> using namespace std; void swap(int *x, int *y) { int z = *x; *x = *y; *y = z; } // Driver Code int main() { int a = 45, b = 35; cout << "Before Swap\n"; cout << "a = " << a << " b = " << b << "\n"; swap(&a, &b); cout << "After Swap with pass by pointer\n"; cout << "a = " << a << " b = " << b << "\n"; } ... It allows a function to modify a variable without having to create a copy of it. We have to declare reference variables.
🌐
Abseil
abseil.io › tips › 234
abseil / Tip of the Week #234: Pass by Value, by Pointer, or by Reference?
In C++, if you pass a variable by value, depending on how the function is called the variable’s value may be copied or moved (or neither)[^names]. On the other hand, passing by reference (or pointer) allows you to refer to an existing object and therefore avoid a copy entirely.
🌐
Sololearn
sololearn.com › en › Discuss › 3209319 › pass-by-reference-or-pass-by-pointer
Pass by reference or pass by pointer? | Sololearn: Learn to code for FREE!
Pass by pointer : In this , as a function argument, we pass the addresses of global variables . * In this, we need to change our global variables so we pass global variables addresses . As an example, we created a function for swap two no function, and then we need to Pass it's global variables addresses, not variables reference (values ) otherwise in function local variables will be swap but when we print it in main then it's normal as like before 😏
Find elsewhere
🌐
TechGeekBuzz
techgeekbuzz.com › blog › pass-by-reference-vs-pass-by-pointer-in-cpp
Pass by Reference vs Pass by Pointer in C++ [Differences]
In other words, pass by reference means passing the memory location of the variables to the parameters in the function and then performing computations. Let us implement the pass by pointer method in the following example. Also, we obtained the same results when implemented using pass by reference.
🌐
DevGenius
blog.devgenius.io › pass-by-value-and-pass-by-reference-in-c-15c4393eb675
Passing By Pointer vs Passing By Reference in C++ | by Nitish Singh | Dev Genius
2 weeks ago - Passing By Pointer vs Passing By Reference in C++ In C++, functions can receive arguments in three common ways: By value By reference By address (pointer) Each approach has different performance …
🌐
Cplusplus
cplusplus.com › forum › beginner › 261042
When to use pointers and references? - C++ Forum
August 30, 2019 - Passing/variables by pointer is faster because it does not make a copy. It also allows the pointer variable to be changed at the root of the function. Passing/variables by reference is similar to pointers but they cannot be reassigned and are aliases instead of memory addresses.
Top answer
1 of 3
20

When you pass a parameter by reference, the parameter inside the function is an alias to the variable you passed from the outside. When you pass a variable by a pointer, you take the address of the variable and pass the address into the function. The main difference is that you can pass values without an address (like a number) into a function which takes a const reference, while you can't pass address-less values into a function which takes const pointers.

Typically a C++ compiler implement a reference as a hidden pointer.

You can change your function into the pointer variant this way:

void flip(int *i) // change the parameter to a pointer type
{
    cout << "          flip start "<<"i="<< *i<<"\n"; // replace i by *i
    *i = 2*(*i); // I'm not sure it the parenthesis is really needed here,
                 // but IMHO this is better readable
    cout << "          flip exit  "<<"i="<< *i<<"\n";
}

int main()
{
    int j =1;
    cout <<"main j="<<j<<endl;
    flip(&j); // take the address of j and pass this value
    // adjust all other references ...
}
2 of 3
1

For the second part of your question, here is the code.

#include <iostream>
#include <cassert>

using namespace std;

void flip(int *i)
{
    cout << "          flip start "<<"i="<< i<<"\n";
    *i *= 2;
    cout << "          flip exit  "<<"i="<< i<<"\n";
}

int main()
{
    int j =1;
    cout <<"main j="<<j<<endl;
    flip(&j);
    cout <<"main j="<<j<<endl;
    flip(&j);
    cout <<"main j="<<j<<endl;
    flip(&j);
    cout <<"main j="<<j<<endl;

    assert(j==8);

    return 0;
}

For the first part of your question, I am new to C++ but I find it useful to pass by pointer when having to return multiple outputs for a function. Or to pass NULL as a parameter.

🌐
PREP INSTA
prepinsta.com › home › c++ online tutorials › passing by pointer vs passing by reference
Passing by Pointer VS Passing by Reference | PrepInsta
February 2, 2023 - Whereas on the other hand, when you pass an argument to a function by pointer, you are passing a pointer to the memory location of the argument. Passing by reference means that if you change the value of the argument inside the function, the ...
🌐
IBM
ibm.com › docs › en › zos › 2.4.0
Pass by reference (C++ only) - IBM Documentation
April 8, 2021 - The difference between pass-by-reference and pass-by-pointer is that pointers can be NULL or reassigned whereas references cannot. Use pass-by-pointer if NULL is a valid parameter value or if you want to reassign the pointer.
🌐
Quora
quora.com › What-is-the-difference-between-pass-by-reference-and-pass-by-pointers-to-a-function
What is the difference between pass by reference and pass by pointers to a function? - Quora
Answer (1 of 8): Pass by pointer is the only way you could pass "by reference" in C, so you still see it used quite a bit. The NULL pointer is a handy convention for saying a parameter is unused or not valid, so use a pointer in that case.
🌐
Sololearn
sololearn.com › en › Discuss › 1702528 › pass-by-reference-vs-pass-by-pointer
Pass by reference VS pass by pointer | Sololearn: Learn to code for FREE!
February 25, 2019 - A practical recommendation I have read: When you want to change the value you pass, use a pointer; when you just want to read the data, use a reference but make it const. The point was to keep your code maintainable.
🌐
Medium
medium.com › @lucianoalmeida1 › back-to-basics-pass-by-value-vs-pass-by-ref-96a591c88174
Back to Basics: Pass-by-value vs. Pass-by-Ref | by Luciano Almeida | Medium
August 31, 2023 - But if you are passing a string or a vector which copy means invoking a copy constructor and creating a new vector with all elements, definitely use a reference. If you have an uint8_t for example, and you are compiling targeting a 64-bit platform where a pointer value size is also 64 bits, by passing it by ref we are actually copying a bigger value.
🌐
TutorialsPoint
tutorialspoint.com › passing-by-pointer-vs-passing-by-reference-in-cplusplus
C++ function call by pointer
April 17, 2025 - The call by pointer method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call.
🌐
Weber State University
icarus.cs.weber.edu › ~dab › cs1410 › textbook › 6.Functions › reference.html
6.3.3. Pass-By-Reference
Alternatively, pass-by-reference achieves independence by not passing data at all but by temporarily mapping the parameter name to the argument's memory address. (Advantage) Quite unlike pass-by-pointer, pass-by-reference requires a single, simple syntactical change: adding the ampersand, &, to all reference parameters in the function definition and prototypes.
🌐
Medium
kevin-yang.medium.com › c-pass-by-value-pointer-reference-ddc3780d907c
C++ Pass by Value, Pointer*, &Reference | by Kevin Yang | Medium
May 6, 2019 - There is no new memory being consumed (except for the variable name) and all operations on the reference variable affect the real underlying object being referred to. For example, int count = 0; int& count_ref = count; count++; count_ref++; // count is now 2 · This is powerful because it allows us to pass large objects into functions by giving another name to the object and not copying the large object, while also allowing us avoid the hairy complications of passing by pointer.
🌐
Unreal Engine
forums.unrealengine.com › development › programming & scripting
Pass by reference Vs Pointer - Programming & Scripting - Epic Developer Community Forums
October 19, 2023 - I’m new to this, and it might have been answered before, but I still can’t grasp the distinction between passing by pointer and passing by reference. In Unreal Engine’s source code, they often use pointers, but occasionally use references. Both can be interchanged and still function and it’s the same in terms of performance, as far as I understand.
🌐
Reddit
reddit.com › r/c_programming › in c specifically, is there any advantage to using pass by reference instead of pass by value?
r/C_Programming on Reddit: In C specifically, is there any advantage to using Pass by Reference instead of pass by value?
August 22, 2022 - Passing by reference" in C really means just passing a pointer to a location in memory. A pointer's size depends on the architecture you're targeting, in most modern architectures, a pointer is 8 bytes long.