250+ TOP MCQs on Argument Passing and Answers

This section on tough C++ programming questions on “Argument Passing”. One shall practice these questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ programming questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of tough C++ programming questions on “Argument Passing” along with answers, explanations and/or solutions:

1. How many ways of passing a parameter are there in c++?
a) 1
b) 2
c) 3
d) 4
Answer: c
Clarification: There are three ways of passing a parameter. They are pass by value,pass by reference and pass by pointer.

2. Which is used to keep the call by reference value as intact?
a) static
b) const
c) absolute
d) virtual
Answer: b
Clarification: Because const will not change the value of the variables during the execution.

3. By default how the value are passed in c++?
a) call by value
b) call by reference
c) call by pointer
d) call by object
Answer: a
Clarification: None.

4. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     void copy (int& a, int& b, int& c)
  4.     {
  5.         a *= 2;
  6.         b *= 2;
  7.         c *= 2;
  8.     }
  9.     int main ()
  10.     {
  11.         int x = 1, y = 3, z = 7;
  12.         copy (x, y, z);
  13.         cout << "x =" << x << ", y =" << y << ", z =" << z;
  14.         return 0;
  15.     }

a) 2 5 10
b) 2 4 5
c) 2 6 14
d) 2 4 9
Answer: c
Clarification: Because we multiplied the values by 2 in the copy function.
Output:

$ g++ arg6.cpp
$ a.out
x = 2,y = 6,z = 14

5. What will be the new value of x in the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     void fun(int &x)
  4.     {
  5.         x = 20;
  6.     }
  7.     int main()
  8.     {
  9.          int x = 10;
  10.          fun(x);
  11.          cout << "New value of x is " << x;
  12.          return 0;
  13.     }

a) 10
b) 20
c) 15
d) 36
Answer: b
Clarification: As the parameter is passed by reference, the value in the original memory of x is changed hence the output is printed as 20.
Output:

$ g++ arg5.cpp
$ a.out
20

6. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     long factorial (long a)
  4.     {
  5.         if (a > 1)
  6.             return (a * factorial (a + 1));
  7.         else
  8.             return (1);
  9.     }
  10.     int main ()
  11.     {
  12.         long num = 3;
  13.         cout << num << "! = " << factorial ( num );
  14.         return 0;
  15.     }

a) 6
b) 24
c) segmentation fault
d) compile time error
Answer: c
Clarification: As we have given in the function as a+1, it will exceed the size and so it arises the segmentation fault.
Output:

$ g++ arg3.cpp
$ a.out
segmentation fault