That is taking the parameter by reference. So in the first case you are taking a pointer parameter by reference so whatever modification you do to the value of the pointer is reflected outside the function. Second is the simlilar to first one with the only difference being that it is a double pointer. See this example:
void pass_by_value(int* p) { //Allocate memory for int and store the address in p p = new int; } void pass_by_reference(int*& p) { p = new int; } int main() { int* p1 = NULL; int* p2 = NULL; pass_by_value(p1); //p1 will still be NULL after this call pass_by_reference(p2); //p2 's value is changed to point to the newly allocate memory return 0; }
Related Posts:
- Are the C++ & and * operators inverses in all contexts?
- how does the ampersand(&) sign work in c++?
- When should I use the new keyword in C++?
- What are the differences between a pointer variable and a reference variable in C++?
- lvalue required as left operand of assignment error when using C++
- Arrow operator (->) usage in C
- What does `*&` in a function declaration mean?
- What’s the difference between char and char* in C++?
- initial value of reference to non-const must be an lvalue
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- Reference to non-static member function must be called
- What does ** mean in C?
- C++ pass an array by reference
- What does ‘return *this’ mean in C++?
- Is C++ Array passed by reference or by pointer?
- Linker Error C++ “undefined reference ” [duplicate]
- Return array in a function
- What does “dereferencing” a pointer mean?
- Regular cast vs. static_cast vs. dynamic_cast
- What is a smart pointer and when should I use one?
- What does “dereferencing” a pointer mean?
- What is a char*?
- What exactly is nullptr?
- What does ‘&’ do in a C++ declaration?
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- How to fix a “invalid operands to binary expression” error?
- Undefined Symbols for architecture x86_64: Compiling problems
- What is a dangling pointer?
- (->) arrow operator and (.) dot operator , class pointer
- Pass a vector by reference C++
- What is uintptr_t data type
- What is the difference between const int*, const int * const, and int const *?
- C++ – No matching member function for call to ‘push_back’
- What is uintptr_t data type
- What does int & mean
- What is the difference between const int*, const int * const, and int const *?
- Difference between const reference and normal parameter
- Pointer to incomplete class type is not allowed
- Passing by reference in C
- Why does the arrow (->) operator in C exist?
- Passing a 2D array to a C++ function
- Is the practice of returning a C++ reference variable evil?
- How do you pass a function as a parameter in C?
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- How to access the contents of a vector from a pointer to the vector in C++?
- How do you pass a function as a parameter in C?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- expression must have integral type
- How do you pass a function as a parameter in C?
- What does int & mean
- C++: Expression must have a constant value when declaring array inside function
- What’s the syntax for declaring an array of function pointers without using a separate typedef?
- Sorting Linked List C++ with pointers
- Delete 2D array C++
- Is the sizeof(some pointer) always equal to four?
- What are the distinctions between the various symbols (*,&, etc) combined with parameters?
- C++ Expression must have pointer-to-object type
- C++ strings and pointers
- Typedef function pointer?
- How to initialize a vector of pointers
- How to printf a memory address in C
- What is the use of intptr_t?
- Error: No instance of constructor matches the argument list
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- C++ – Assigning null to a std::string
- How to convert const char* to char* in C?
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- Why use pointers?
- C++ Return value, reference, const reference
- What’s the difference between * and & in C?
- Invalid type argument of -> C structs
- How to create a vector of class objects in C++?
- Get size of pointer in C
- C: pointer to array of pointers to structures (allocation/deallocation issues)
- Function stoi not declared
- Casting a pointer to an int
- C++ Array of pointers: delete or delete []?
- Why should I use a pointer rather than the object itself?
- Function stoi not declared
- C++ correct way to return pointer to array from function
- Warning: comparison of distinct pointer types
- Is null reference possible?
- Initializing pointers in C++
- Why am I getting an ‘Else without previous if’ error within a for loop?
- Why can’t I make a vector of references?
- Difference between function arguments declared with & and * in C++
- Difference between the int * i and int** i
- set head to NULL (‘NULL’ : undeclared identifier)
- What is a `char*`?
- Why virtual & static keywords aren’t allowed outside class declaration?
- clearing a vector of pointers [duplicate]
- C – Error is “free(): invalid next size (normal) “
- C++ Swapping Pointers
- Initialization makes pointer from integer without a cast – C
- Array of Linked Lists C++
- Differences between unique_ptr and shared_ptr
- C++ Vector of pointers
- What is activation record in the context of C and C++?
- What’s the meaning of exception code “EXC_I386_GPFLT”?