The difference is more prominent when you are passing a big struct/class.
struct MyData { int a,b,c,d,e,f,g,h; long array[1234]; }; void DoWork(MyData md); void DoWork(const MyData& md);
when you use use ‘normal’ parameter, you pass the parameter by value and hence creating a copy of the parameter you pass. if you are using const reference, you pass it by reference and the original data is not copied.
in both cases, the original data cannot be modified from inside the function.
EDIT:
In certain cases, the original data might be able to get modified as pointed out by Charles Bailey in his answer.
Related Posts:
- Linker Error C++ “undefined reference ” [duplicate]
- What are the differences between a pointer variable and a reference variable in C++?
- What is meant with “const” at end of function declaration? [duplicate]
- What does int argc, char *argv[] mean?
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Difference between `constexpr` and `const`
- What does `*&` in a function declaration mean?
- Pass a vector by reference C++
- What is the difference between const int*, const int * const, and int const *?
- What is the difference between const int*, const int * const, and int const *?
- invalid use of non-static member function
- How to convert a std::string to const char* or char*
- What is the difference between a static and const variable?
- How can I convert const char* to string and then back to char*?
- Is the practice of returning a C++ reference variable evil?
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- C++: Expression must have a constant value when declaring array inside function
- What is the difference between const_iterator and non-const iterator in the C++ STL?
- error: “initializer expression list treated as compound expression”
- initial value of reference to non-const must be an lvalue
- Error: No instance of constructor matches the argument list
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- 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
- C++ Return value, reference, const reference
- C++ pass an array by reference
- How to create a vector of class objects in C++?
- How to sort with a lambda?
- got “cannot appear in a constant-expression” when using template
- non-member function cannot have cv-qualifier
- Where to declare/define class scope constants in C++?
- Is null reference possible?
- Use of ‘const’ for function parameters
- Why can’t I make a vector of references?
- Is C++ Array passed by reference or by pointer?
- Pause Console in C++ program
- Why the switch statement cannot be applied on strings?
- How to dynamically allocate arrays in C++
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Why is “using namespace std;” considered bad practice?
- Good input validation loop using cin – C++
- Are the C++ & and * operators inverses in all contexts?
- C++ for each, pulling from vector elements
- How do I erase an element from std::vector<> by index?
- Incomplete Type Is Not Allowed
- how to implement quick sort algorithm in C++
- C++ Vector of pointers
- How do I reverse a C++ vector?
- Is there a C++ decompiler?
- What is uintptr_t data type
- const int = int const?
- Undefined reference to vtable
- In C++, what is a virtual base class?
- wntdll.pdb not loaded – Can’t see the exception
- SDL2.DLL missing
- Parsing a comma-delimited std::string
- Random number c++ in some range
- “g++” is not recognized as an internal or external command, MinGW
- Compiling a C++ program with gcc
- What’s the syntax for declaring an array of function pointers without using a separate typedef?
- Sorting Linked List C++ with pointers
- Get Unix timestamp with C++
- Class prototyping
- How to dynamically allocate an array of pointers in C++?
- How do I compile C++ to JavaScript in a browser?
- Is the sizeof(some pointer) always equal to four?
- How do you initialise a dynamic array in C++?
- What are the distinctions between the various symbols (*,&, etc) combined with parameters?
- C++ Simple hangman game
- “The system cannot find the file specified” when running C++ program
- Remove First and Last Character C++
- C++ Convert string (or char*) to wstring (or wchar_t*)
- Program received signal SIGSEGV, Segmentation fault
- Integer to hex string in C++
- Comparison of C++ unit test frameworks
- What is the difference between .cc and .cpp file suffix?
- C++ error: object of abstract class type is not allowed: pure virtual function has no overrider
- Correct way to work with vector of arrays
- What’s the difference between nexti and stepi in gdb?
- How to get current time in milliseconds?
- Resizing dynamic array in c++
- Trying to use int in getline
- c++ error c2015: too many characters in constant
- Splitting a C++ std::string using tokens, e.g. “;”
- Py_Initialize fails – unable to load the file system codec
- error LNK2019: unresolved external symbol “” referenced in function
- Undefined reference to a static member
- How to do std::string indexof in C++ that returns index of matching string?
- variable or field declared void
- Invalid conversion from ‘char’ to ‘const char *’
- How do I deal with “signed/unsigned mismatch” warnings (C4018)?
- Creating folders in C++
- Unrecognizable template declaration/definition
- heap corruption detected | C++
- Update g++ but still old version
- module unsafe for SAFESEH image C++
- Why are there two different getline() functions (if indeed there are)?
- Whats the difference between UInt8 and uint8_t
- Struct with template variables in C++