Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void Sum(int a, int b, int & c)
4.
{
5.
a = b + c;
6.
b = a + c;
7.
c = a + b;
8.
}
9.
int main()
10.
{
11.
int x = 2, y =3;
12.
Sum(x, y, y);
13.
cout
  1.    2 3
  2.    6 9
  3.    2 15
  4.    compile time error
 Discuss Question
Answer: Option C. -> 2 15

We have passed three values and it will manipulate according to the given condition and yield 

the result as 2 15
Output:
$ g++ arg.cpp
$ a.out
2 15


Question 2.

What will happen when we use void in argument passing?


  1.    It will not return value to its caller
  2.    It will return value to its caller
  3.    both a & b are correct
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> It will not return value to its caller

As void is not having any return value, it will not return the value to the caller.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int add(int a, int b);
4.
int main()
5.
{
6.
int i = 5, j = 6;
7.
cout
  1.    11
  2.    12
  3.    13
  4.    compile time error
 Discuss Question
Answer: Option C. -> 13

The value of a has been changed to 7, So it returns as 13.
Output:
$ g++ arg1.cpp
$ a.out
13


Question 4.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
void square (int *x)
4.
{
5.
*x = (*x + 1) * (*x);
6.
}
7.
int main ( )
8.
{
9.
int num = 10;
10.
square(&num);
11.
cout
  1.    100
  2.    compile time error
  3.    144
  4.    110
 Discuss Question
Answer: Option D. -> 110

We have increased the x value in operand as x+1, so it will return as 110.
Output:
$ g++ arg2.cpp
$ a.out
110


Question 5.


What is the output of this program?


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
  1.    6
  2.    24
  3.    segmentation fault
  4.    compile time error
 Discuss Question
Answer: Option C. -> segmentation fault

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


Question 6.


What is the new value of x?


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
  1.    10
  2.    20
  3.    15
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> 20

As we passed by reference, the value is changed and it is returned as 20.
Output:
$ g++ arg5.cpp
$ a.out
20


Question 7.

By default how the value are passed in c++?


  1.    call by value
  2.    call by reference
  3.    call by pointer
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> call by value

None.


Question 8.


What is the output of this program?


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
  1.    2 5 10
  2.    2 4 5
  3.    2 6 14
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> 2 6 14

Because we multiplied the values by 2 in the copy function.
Output:
$ g++ arg6.cpp
$ a.out
x = 2,y = 6,z = 14


Question 9.

How many ways of passing a parameter are there in c++?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option C. -> 3

There are three ways of passing a parameter. They are pass by value,pass by reference and 

pass by pointer.


Question 10.

Which is used to keep the call by reference value as intact?


  1.    static
  2.    const
  3.    absolute
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> const

Because const will not change the value of the variables during the execution.


Latest Videos

Latest Test Papers