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?
- Is “delete this” allowed in C++?
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- How to create a dynamic array of integers
- How to create a dynamic array of integers
- How do I build a graphical user interface in C++? [closed]
- C++ convert from 1 char to string?
- How do I build a graphical user interface in C++? [closed]
- convert a char* to std::string
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- How to implement 2D vector array?
- Why the switch statement cannot be applied on strings?
- What is the difference between g++ and gcc?
- How to use setprecision in C++
- How to dynamically allocate arrays in C++
- What does (~0L) mean?
- How to dynamically allocate arrays in C++
- What is the best way to use a HashMap in C++?
- What is the best way to use a HashMap in C++?
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Sleep for milliseconds
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- What is the difference between float and double?
- Why is “using namespace std;” considered bad practice?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- outputting ascii table in C++
- What is a lambda expression in C++11?
- Vector of Vectors to create matrix
- How to throw a C++ exception
- std::string to char*
- How to generate a random number in C++?
- pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- How do I find the length of an array?
- Sleep for milliseconds
- How to convert string to char array in C++?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- What is the effect of extern “C” in C++?
- C++ Cout & Cin & System “Ambiguous” [closed]
- ld: symbol(s) not found for architecture x86_64 error
- C++ string to double conversion
- Why are #ifndef and #define used in C++ header files?
- g++ ld: symbol(s) not found for architecture x86_64
- What exactly is the difference between “pass by reference” in C and in C++?
- How to throw a C++ exception
- Conversion from string to char – c++
- How to find out if an item is present in a std::vector?
- What is meant by Resource Acquisition is Initialization (RAII)?
- When to use extern “C” in simple words? [duplicate]
- What is `CString`?
- Floating point exception( core dump
- Initializing an array of objects
- Passing Arrays to Function in C++
- What does the explicit keyword mean?
- How do I print out the contents of a vector?
- Difference between != and =! with an example(in C++)
- Expression must have class type
- The static keyword and its various uses in C++
- Passing an array by reference