Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

What is the importance of mutable keyword?


  1.    It allows the data member to change within a const member function.
  2.    It will not allow the data member to change within a const member function.
  3.    It will copy the values of the variable.
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> It allows the data member to change within a const member function.

Mutable keyword allows assigning values to a data member belonging to a class defined as 

"Const" or constant.


Question 2.

What is the default access level to a block of data?


  1.    Public
  2.    Protected
  3.    Private
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Private

None.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
struct X;
4.
struct Y
5.
{
6.
void f(X*);
7.
};
8.
struct X
9.
{
10.
private:
11.
int i;
12.
public:
13.
void initialize();
14.
friend void g(X* , int);
15.
friend void Y :: f(X*);
16.
friend struct Z;
17.
friend void h();
18.
};
19.
void X :: initialize()
20.
{
21.
i = 0;
22.
}
23.
void g(X* x, int i)
24.
{
25.
x -> i = i;
26.
}
27.
void Y :: f(X * x)
28.
{
29.
x -> i = 47;
30.
cout i;
31.
}
32.
struct Z
33.
{
34.
private:
35.
int j;
36.
public:
37.
void initialize();
38.
void g(X* x);
39.
};
40.
void Z::initialize()
41.
{
42.
j = 99;
43.
}
44.
void Z::g(X* x)
45.
{
46.
x -> i += j;
47.
}
48.
void h()
49.
{
50.
X x;
51.
x.i = 100;
52.
cout
  1.    99
  2.    47
  3.    Data accessed
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Data accessed

In this program, We are using the access specifiers to friend function to manipulate the values.
Output:
$ g++ acc3.cpp
$ a.out
Data accessed


Question 4.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class Cat
4.
{
5.
public:
6.
int age;
7.
int weight;
8.
};
9.
int main()
10.
{
11.
Cat f;
12.
f.age = 56;
13.
cout
  1.    Gates is
  2.    Gates is 56 years old
  3.    Error
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Gates is 56 years old

In this program, We passed the value from main function to class and returning it to the main 

and then printing it.
Output:
$ g++ acc2.cpp
$ a.out
Gates is 56 years old


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
struct A
4.
{
5.
private:
6.
int i, j, k;
7.
public:
8.
int f();
9.
void g();
10.
};
11.
int A :: f()
12.
{
13.
return i + j + k;
14.
}
15.
void A :: g()
16.
{
17.
i = j = k = 0;
18.
}
19.
class B
20.
{
21.
int i, j, k;
22.
public:
23.
int f();
24.
void g();
25.
};
26.
int B :: f()
27.
{
28.
return i + j + k;
29.
}
30.
void B :: g()
31.
{
32.
i = j = k = 0;
33.
}
34.
int main()
35.
{
36.
A a;
37.
B b;
38.
a.f();
39.
a.g();
40.
b.f();
41.
b.g();
42.
cout
  1.    50
  2.    Identical results would be produced
  3.    Error
  4.    Runtime error
 Discuss Question
Answer: Option B. -> Identical results would be produced

In this program, We apply the access specifiers to both the class and the structure.
Output:
$ g++ acc1.cpp
$ a.out
Identical results would be produced


Question 6.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class student
4.
{
5.
public:
6.
int rno , m1 , m2 ;
7.
protected:
8.
void get()
9.
{
10.
rno = 15, m1 = 10, m2 = 10;
11.
}
12.
};
13.
class sports
14.
{
15.
public:
16.
int sm;
17.
void getsm()
18.
{
19.
sm = 10;
20.
}
21.
};
22.
class statement : public student, public sports
23.
{
24.
int tot, avg;
25.
public:
26.
void display()
27.
{
28.
tot = (m1 + m2 + sm);
29.
avg = tot / 3;
30.
cout
  1.    3010
  2.    1010
  3.    2100
  4.    Error
 Discuss Question
Answer: Option A. -> 3010

None.


Question 7.

To which of the following access aspecifiers are applicable?


  1.    Member data
  2.    Functions
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Both a & b

The access specifiers can be applicable to the member data and functions because they need 

to be accessed outside the block.


Question 8.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
struct A
4.
{
5.
int i;
6.
char j;
7.
float f;
8.
void func();
9.
};
10.
void A :: func() {}
11.
struct B
12.
{
13.
public:
14.
int i;
15.
char j;
16.
float f;
17.
void func();
18.
};
19.
void B :: func() {}
20.
int main()
21.
{
22.
A a; B b;
23.
a.i = b.i = 1;
24.
a.j = b.j = 'c';
25.
a.f = b.f = 3.14159;
26.
a.func();
27.
b.func();
28.
cout
  1.    Allocated
  2.    Error
  3.    3.14159
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Allocated

In this program, We used access specifiers for structures, As we declared all methods as public, 

The values can be allocated.
Output:
$ g++ acc.cpp
$ a.out
Allocated


Question 9.

How many access specifiers are there in c++?


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

There are three access specifiers in c++. They are public, Private and Protected.


Question 10.

What of the following describes protected access specifier?


  1.    The variable is visible only outside inside the block
  2.    The variable is visible everywhere
  3.    The variable is visible to its block and to it’s derived class
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> The variable is visible to its block and to it’s derived class

None.


Latest Videos

Latest Test Papers