Functions Parameter Passing in C ++ Programming MCQ Questions and Answers

1. Which parameter passing mechanism makes a copy of the argument so the called function cannot modify the caller’s original object?
A) Call by value
B) Call by reference
C) Call by pointer
D) Call by rvalue reference
Answer: A

2. Which parameter type allows a function to modify the original argument and does not require dereferencing in the function body?
A) Call by value
B) Call by pointer
C) Call by reference
D) Constant value
Answer: C

3. What happens to an array argument when passed to a function declared as void f(int a[])?
A) The entire array is copied element-by-element.
B) The function receives the number of elements only.
C) The array decays to a pointer to its first element.
D) The array is wrapped into a std::vector automatically.
Answer: C

4. Which function parameter declaration prevents the function from modifying the passed argument but avoids copying for large objects?
A) T
B) T*
C) T&
D) const T&
Answer: D

5. Given void f(int &x), which call is invalid?
A) int a = 5; f(a);
B) f(*ptr); where ptr is int* and not null
C) f(std::move(a)); where a is int
D) const int b = 7; f(b);
Answer: D

6. Which of the following permits passing a nullptr to the function parameter?
A) void f(int &x)
B) void f(const int &x)
C) void f(int *x)
D) void f(int x)
Answer: C

7. Which parameter passing method is most appropriate when you need to accept both lvalues and rvalues without copying for modern C++ move semantics?
A) T (by value)
B) T& (lvalue reference)
C) const T&
D) T&& (rvalue reference)
Answer: D

8. Which of the following function parameter declarations will bind to temporary objects (prvalues)?
A) T&
B) T*
C) const T&
D) T&& only if the function is noexcept
Answer: C

9. Consider void f(std::string s); and void g(const std::string &s); — which statement is correct about passing a temporary std::string(“x”)?
A) f avoids a copy, g makes a copy.
B) f may use move-construction; g binds to the temporary without copying.
C) Both always copy the temporary.
D) Both always move the temporary.
Answer: B

10. What is the effect of marking a pointer parameter as int * const p in a function?
A) The function cannot modify the integer pointed to.
B) The function cannot change what p points to (the pointer is const).
C) The pointer itself is const inside the function; the pointee can be modified.
D) Both pointer and pointee are const.
Answer: C

11. Which parameter type is commonly used to implement optional output parameters in legacy C++ code (pre-std::optional)?
A) T
B) const T&
C) T&&
D) T* (pointer used as out parameter)
Answer: D

12. When a function signature is void f(int a, int b = 10); and it is called as f(3);, which value does b have?
A) Undefined
B) 0
C) 10
D) 3
Answer: C

13. Which of these is true about passing function pointers as parameters: void caller(void (*fp)(int))?
A) You must always pass a std::function.
B) You can pass a lambda with captures directly.
C) You can pass a plain function or a captureless lambda that matches the signature.
D) You cannot pass member functions at all.
Answer: C

14. Which of the following parameter types will extend the lifetime of a temporary to the duration of the reference?
A) T&
B) T*
C) const T&
D) T&& never extends lifetime
Answer: C

15. For the signature void f(const int* p), which statement is correct?
A) f can modify the integer pointed to.
B) f can change pointer p as seen by the caller.
C) f cannot modify the integer pointed to, but can change its local copy of p.
D) p must not be nullptr.
Answer: C

16. What is the primary risk of returning a reference to a function parameter that was passed by value? Example: T& g(T x) { return x; }
A) Extra copies.
B) It is always optimized away.
C) Dangling reference to a local variable (undefined behavior).
D) The caller can modify the caller’s original object.
Answer: C

17. Which declaration allows a function to accept a variable number of arguments of arbitrary types (C-style)?
A) void f(…)
B) template<typename… Args> void f(Args… args)
C) Both A and B are true but A is the old C-style ellipsis.
D) void f(std::variant<…> args)
Answer: C

18. Which parameter passing style best expresses “I will not modify this heavy object and also avoid copying”?
A) T
B) T&
C) const T&
D) T* const
Answer: C

19. If a function expects void f(std::initializer_list<int> vals), what kind of argument can you pass?
A) Only std::vector<int>
B) A braced list like {1,2,3}
C) Only arrays of compile-time size
D) Only int* and size separately
Answer: B

20. Which of the following makes the most sense when implementing copy-and-swap idiom for operator= to get strong exception safety?
A) Accept by T& and modify directly.
B) Accept by value (copy), then swap with *this.
C) Accept by T* and modify pointer contents.
D) Accept by const T& and then throw on error.
Answer: B

21. What does std::move do to a function argument when you write f(std::move(x))?
A) Physically move memory immediately.
B) Make a copy of x.
C) Cast x to an rvalue-reference allowing move constructors/assignments to be chosen.
D) Delete x.
Answer: C

22. Which of the following correctly describes binding a non-const lvalue reference?
A) It can bind to temporaries.
B) It requires an lvalue (named object) to bind.
C) It can bind to const objects only.
D) It can bind to nullptr.
Answer: B

23. Consider void f(int&& x); Which of the following is true?
A) f(a) where a is an int lvalue compiles without changes.
B) f(5) (a prvalue) will bind to x.
C) f(std::move(a)) will not bind.
D) f can be called with nullptr.
Answer: B

24. Given void swap(T& a, T& b); which call is valid?
A) swap(1,2);
B) swap(a, 2); where a is an lvalue T
C) swap(x, y); where x and y are lvalues of type T.
D) swap(std::move(x), std::move(y)); where x,y are lvalues — always safe with this signature.
Answer: C

25. What is the difference between void f(T) and void f(T&) in terms of lifetime and copying?
A) No difference — both avoid copying.
B) T avoids copying; T& always copies.
C) T makes a copy (new lifetime inside function); T& binds to the original without copying.
D) T binds to the original; T& binds to a temporary only.
Answer: C

26. Which parameter passing technique is most efficient for small primitive data types like int or char?
A) Call by reference
B) Call by pointer
C) Call by value
D) Call by constant reference
Answer: C

27. Which keyword ensures that a reference parameter cannot be modified inside a function?
A) static
B) mutable
C) volatile
D) const
Answer: D

28. What will happen if you pass a large object by value to a function?
A) It will always move instead of copy.
B) The compiler will automatically convert to reference.
C) It will make a full copy of the object.
D) It will modify the original object.
Answer: C

29. Which of the following can be used to pass a parameter that can optionally be null?
A) T&
B) T&&
C) T*
D) const T&
Answer: C

30. What is the result of passing a const int by reference to a function taking int&?
A) It will compile and modify the value.
B) It will compile but not modify the value.
C) It will cause a compilation error.
D) It will convert automatically to a pointer.
Answer: C

31. What is the purpose of using default parameter values in functions?
A) To overload the function for all parameter counts
B) To allow function calls with fewer arguments
C) To define constants inside the function
D) To force inline expansion
Answer: B

32. What will be the output of the following snippet?
void f(int x) { x = 10; }
int main() { int a = 5; f(a); cout << a; }
A) 10
B) Garbage
C) 5
D) Compiler error
Answer: C

33. Which of these statements is true for passing parameters by reference in C++?
A) The function gets a copy of the argument.
B) The function can modify the caller’s variable directly.
C) The argument must be a pointer.
D) The parameter is stored in a different memory address.
Answer: B

34. Which of the following supports both input and output through the same parameter?
A) Call by value
B) Call by reference
C) Call by default
D) Call by copy
Answer: B

35. When passing a pointer as a parameter, what does the pointer variable inside the function actually contain?
A) A copy of the value pointed to
B) A copy of the address of the argument
C) The actual memory location of the argument
D) The reference to a constant address
Answer: B

36. Which parameter passing mechanism allows indirect modification using the dereference operator?
A) Call by value
B) Call by pointer
C) Call by copy
D) Call by name
Answer: B

37. Which function prototype is invalid in C++?
A) void f(int = 0, int = 1);
B) void f(int = 0, int);
C) void f(int x = 0);
D) void f();
Answer: B

38. Which statement about inline functions with parameters is correct?
A) They cannot take parameters.
B) Inline applies only to functions without parameters.
C) They can take parameters like any other function.
D) They must pass parameters by value.
Answer: C

39. What is the main benefit of using const reference parameters?
A) To make function faster for arithmetic
B) To enforce passing only constant literals
C) To avoid copying large data while ensuring immutability
D) To allocate memory dynamically
Answer: C

40. When a parameter is declared as int * const ptr, what does it mean?
A) The pointer cannot point to another location.
B) The value pointed to cannot be changed.
C) Both pointer and pointee are constant.
D) The pointer can be reassigned freely.
Answer: A

41. In modern C++, which syntax is preferred to express that a function may take ownership of a resource temporarily?
A) T&
B) T&&
C) const T&
D) T* const
Answer: B

42. Which mechanism helps implement polymorphic behavior by passing base class references?
A) Pass by value
B) Pass by reference
C) Pass by pointer only
D) Pass by template
Answer: B

43. Which of the following is a valid function overload based only on parameter passing style?
A) void f(int); and void f(int&);
B) void f(int); and void f(const int&);
C) void f(int*); and void f(int*);
D) None are valid
Answer: B

44. In C++, default arguments must be defined:
A) At the end of the parameter list
B) Anywhere in the parameter list
C) Only for trailing parameters (from rightmost side)
D) For every parameter
Answer: C

45. Which parameter passing type avoids the problem of pointer dereferencing but allows modification?
A) Call by pointer
B) Call by value
C) Call by reference
D) Call by constant reference
Answer: C

46. What happens when a parameter is passed as const T* ptr?
A) The pointer cannot be reassigned.
B) The object pointed to cannot be modified via the pointer.
C) The pointer is both const and volatile.
D) It behaves as pass by value.
Answer: B

47. Which of the following represents a correct parameter for output-only data?
A) const int& result
B) int value
C) int* result
D) const int* value
Answer: C

48. What is the outcome of modifying a variable through a pointer parameter inside a function?
A) No effect on the caller
B) Changes the caller’s variable through its address
C) Creates a local copy
D) Causes runtime error
Answer: B

49. In the expression void func(const int &x), what is the key property of x?
A) It must always be a temporary.
B) It cannot be modified inside the function.
C) It is copied each time it is passed.
D) It can point to null.
Answer: B

50. Which of the following is true about function arguments in recursion?
A) They cannot be passed by reference.
B) Each recursive call creates new copies for value parameters.
C) Parameters are shared among all recursive calls.
D) Reference parameters are always reinitialized.
Answer: B

51. When a function is declared as void update(int &a), and called as update(x);, what happens?
A) x is copied before modification.
B) A temporary variable is passed.
C) The original variable x is modified directly.
D) Function receives a null reference.
Answer: C

52. Which of the following statements is true about the const keyword used with references?
A) It prevents binding to temporaries.
B) It prevents modification of the referred object.
C) It prevents parameter passing.
D) It must be used only with pointers.
Answer: B

53. Which of the following is the most memory-efficient way to pass a std::vector<int> if no modification is needed?
A) By value
B) By pointer
C) By const reference
D) By non-const reference
Answer: C

54. When passing a struct by value to a function, which of the following occurs?
A) The address is passed automatically.
B) A copy of the entire structure is made.
C) Only the first member is copied.
D) The compiler converts it to a pointer implicitly.
Answer: B

55. What will the following function print?
void test(int &x) { x += 5; }
int main() { int a = 10; test(a); cout << a; }
A) 5
B) 10
C) 15
D) 0
Answer: C

56. Which parameter passing style is used in the C programming language by default?
A) Call by reference
B) Call by pointer
C) Call by value
D) Call by name
Answer: C

57. What will be the result of the following code?
void f(int *p) { *p = 20; }
int main() { int a = 5; f(&a); cout << a; }
A) 5
B) 10
C) 20
D) Compilation error
Answer: C

58. Which of the following cannot be passed by reference?
A) Variable
B) Object
C) Literal value
D) Array
Answer: C

59. What is the advantage of passing objects by reference rather than by value?
A) Avoids multiple constructors
B) Avoids object copying overhead
C) Avoids the use of pointers
D) Avoids runtime binding
Answer: B

60. What does “passing by pointer” mean in C++?
A) Function receives an alias of the variable.
B) Function receives the memory address of the argument.
C) Function copies the value.
D) Function binds to a reference variable.
Answer: B

61. Which of these can bind to both lvalue and rvalue arguments without copying in C++11 and later?
A) T&
B) const T&
C) const T& and T&&
D) T only
Answer: C

62. In which scenario is “call by value” preferred over “call by reference”?
A) Large data objects
B) Arrays
C) Small primitive data types
D) Objects with dynamic memory
Answer: C

63. If a function accepts parameters as void func(const int* p), what can it do?
A) Modify *p
B) Reassign p but not modify the value it points to
C) Modify both p and *p
D) Change the caller’s variable
Answer: B

64. What will happen when the same parameter is passed by value to two recursive function calls?
A) Both calls modify the same variable.
B) Each call gets a separate copy of the parameter.
C) The first call shares data with the second.
D) Undefined behavior occurs.
Answer: B

65. When you pass an array to a function in C++, what is actually passed?
A) A copy of the entire array
B) A pointer to the first element of the array
C) The array’s length
D) The array’s reference
Answer: B

66. When a parameter is passed by value, what happens to the local variable inside the function?
A) It acts as an independent copy of the argument.
B) It always modifies the original value.
C) It holds the address of the argument.
D) It points to a global copy.
Answer: A

67. What is the difference between int* and int& when used as function parameters?
A) Both mean the same thing.
B) Pointer requires explicit dereference, reference does not.
C) Reference must store a null address.
D) Pointer is faster.
Answer: B

68. What happens if you declare a function parameter as T&& and pass an lvalue?
A) It binds directly.
B) It binds only if there is an T& overload available.
C) It binds automatically.
D) It causes runtime error.
Answer: B

69. When should you prefer const T& over T in function parameters?
A) When passing integers
B) When passing large objects or to avoid copying
C) When pointer syntax is not allowed
D) Always
Answer: B

70. Which statement is correct for the below function?
void g(int * const p) { *p = 50; }
A) The pointer can be reassigned.
B) The pointer is fixed, but the pointee can be changed.
C) The pointee cannot be changed.
D) The pointer is null.
Answer: B

71. Which function declaration allows both int and const int arguments without ambiguity?
A) void f(int&);
B) void f(const int&);
C) void f(int*);
D) void f(const int* const);
Answer: B

72. What does the keyword mutable do when used in a parameter declaration?
A) It allows modification even in const context.
B) It freezes the variable.
C) It prevents copying.
D) It disallows reassignment.
Answer: A

73. When passing a pointer to a function, what ensures that the original pointer’s target is modified?
A) Pass by value
B) Pass by const reference
C) Dereference the pointer within the function
D) Declaring the pointer as static
Answer: C

74. What happens when a temporary object is passed by reference to a non-const parameter?
A) The compiler automatically converts to value.
B) Compilation error: cannot bind temporary to non-const reference.
C) The object is moved.
D) The reference becomes dangling.
Answer: B

75. Which parameter passing method best supports in-place updates without copying and without using pointers?
A) Call by value
B) Call by pointer
C) Call by reference
D) Call by constant reference
Answer: C

76. Which of the following methods of parameter passing in C++ provides the highest level of data protection against modification?
A) Call by value
B) Call by reference
C) Call by constant reference
D) Call by pointer
Answer: C

77. When using call by value, what happens to the actual argument after the function returns?
A) It is modified.
B) It becomes undefined.
C) It remains unchanged.
D) It becomes a reference variable.
Answer: C

78. Which parameter passing technique is not directly supported by C++ but is simulated through macros?
A) Call by value
B) Call by reference
C) Call by pointer
D) Call by name
Answer: D

79. Which one of these statements correctly explains “call by reference”?
A) The function works on the same variable as the caller.
B) The function works on a copy of the variable.
C) The function creates a temporary object.
D) The function returns a reference always.
Answer: A

80. Which of the following is true for passing arrays to functions in C++?
A) Arrays are copied.
B) Only the base address is passed.
C) Both array and length are passed automatically.
D) Arrays are passed by reference.
Answer: B

81. What will the following code output?
void func(int &x) { x *= 2; }
int main() { int n = 3; func(n); cout << n; }
A) 3
B) 6
C) 9
D) Error
Answer: B

82. Which of the following parameter declarations can accept a nullptr as a valid argument?
A) int&
B) int&&
C) int*
D) int const &
Answer: C

83. If a function’s parameter is declared as T&&, and an rvalue is passed, what happens?
A) A copy is made.
B) The function binds directly to the temporary (move semantics).
C) It fails to compile.
D) It creates a dangling reference.
Answer: B

84. Which parameter passing method provides the best balance of safety and efficiency for read-only large objects?
A) By value
B) By pointer
C) By reference
D) By const reference
Answer: D

85. In the code below, which statement is true?
void change(int* p) { *p = 7; }
int main() { int x = 3; change(&x); }
A) x is unchanged.
B) Compiler error occurs.
C) x becomes 7.
D) Pointer becomes null.
Answer: C

86. Which statement about parameter passing in recursive functions is correct?
A) The same copy is used in all calls.
B) Each recursive call creates its own parameter copy.
C) The parameters are global by default.
D) Only reference passing works in recursion.
Answer: B

87. What will the following code print?
void add(int x, int y) { x = x + y; }
int main() { int a = 5, b = 10; add(a, b); cout << a; }
A) 15
B) 10
C) 5
D) 0
Answer: C

88. Which of the following is an invalid way to pass parameters in C++?
A) Pass by value
B) Pass by reference
C) Pass by pointer
D) Pass by result
Answer: D

89. Which statement is true for void func(const int &x)?
A) Function can reassign x.
B) Function can modify the caller’s variable.
C) Function can read but not modify the caller’s value.
D) Function creates a copy of the value.
Answer: C

90. What happens if you pass a string literal to a function expecting char *?
A) It compiles without issue.
B) It gives an error in modern C++ (string literals are const).
C) It converts automatically.
D) It changes the literal.
Answer: B

91. When a reference parameter is used inside a function, it behaves as:
A) An alias for the caller’s variable.
B) A temporary copy.
C) A pointer to a temporary.
D) A constant local variable.
Answer: A

92. What happens if you modify the parameter passed by value?
A) The original value changes.
B) Only the local copy changes.
C) It leads to compilation error.
D) The memory is shared.
Answer: B

93. Which function declaration allows modification of both the pointer and the pointee?
A) void func(const int* p)
B) void func(int* p)
C) void func(int* const p)
D) void func(const int* const p)
Answer: B

94. What is the best reason to use a pointer parameter instead of a reference?
A) To allow nullptr to indicate “no object.”
B) To enforce copy semantics.
C) To make the function inline.
D) To ensure faster performance always.
Answer: A

95. What will happen in this code?
void f(int&& x) { x++; }
int main() { int a = 3; f(std::move(a)); cout << a; }
A) a becomes 4.
B) a remains 3.
C) Compilation error.
D) Runtime error.
Answer: A

96. What does it mean when a function parameter is declared as const T* const ptr?
A) The pointee can change, but pointer cannot.
B) The pointer can change, but pointee cannot.
C) Neither the pointer nor the pointee can change.
D) Both can change.
Answer: C

97. What happens when a function modifies a reference parameter inside a loop?
A) The original variable changes each time.
B) Only a temporary changes.
C) The compiler discards changes.
D) Undefined behavior occurs.
Answer: A

98. Which of the following is a benefit of using parameter passing by reference in recursion?
A) Avoids stack growth.
B) Avoids repeated copying of large data.
C) Allows returning multiple values.
D) Enables tail recursion optimization.
Answer: B

99. Which of the following can accept both lvalue and rvalue arguments efficiently?
A) void f(T&)
B) void f(const T&)
C) template <typename T> void f(T&&)
D) void f(T*)
Answer: C

100. Which parameter passing style ensures that no side effects occur in the caller’s environment?
A) Call by reference
B) Call by pointer
C) Call by value
D) Call by rvalue reference
Answer: C