Which of the following cannot be passed to a function in C++ ?
2017
Which of the following cannot be passed to a function in C++ ?
- A.
Constant
- B.
Structure
- C.
Array
- D.
Header file
Attempted by 215 students.
Show answer & explanation
Correct answer: D
Answer: Header file
Explanation: Header files are source files included at compile time using the #include directive. They are not runtime objects, values, or types that can be passed to a function. You can pass variables, objects, or types that are declared in a header, but not the header file itself.
Constant: You can pass literal values or const-qualified variables to functions by value or by const reference.
Structure: Structs and class objects can be passed by value, by reference, or by pointer; use references or pointers to avoid expensive copies.
Array: C-style arrays decay to pointers when passed to functions (you typically pass a pointer to the first element and the size). Use std::array or std::vector when you need safe pass-by-value semantics.
Short examples: Passing a constant: call a function with 5. Passing a struct: call the function with myStruct or pass a reference/pointer. Passing an array: call the function with arr (it decays to a pointer).