Modifier Types
- What is the importance of mutable keyword?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Mutable keyword allows assigning values to a data member belonging to a class defined as “Const” or constant.
- What is the default access level to a block of data?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Private
- What is the output of this program?
#include <iostream>
using namespace std;
struct A;
struct B
{
void fun1(A*);
};
struct A
{
private:
int k;
public:
void initialize();
friend void fun2(A* , int);
friend void B :: fun1(A*);
friend struct C;
friend void fun3();
};
void A :: initialize()
{
k = 0;
}
void fun2(A* a, int k)
{
a -> k = k;
}
void B :: fun1(A * a)
{
a -> k = 35;
cout << a->k;
}
struct C
{
private:
int L;
public:
void initialize();
void fun2(A* a);
};
void C::initialize()
{
L = 45;
}
void C::fun2(A* a)
{
a -> k += L;
}
void fun3()
{
A a;
a.k = 150;
cout << a.k;
}
int main()
{
A a;
C c;
c.fun2(&a);
cout << "Data accessed";
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We are using the access specifiers to friend function to manipulate the values.
- What is the output of this program?
#include <iostream>
using namespace std;
class Abhay
{
public:
int age;
};
int main()
{
Abhay obj;
obj.age = 24;
cout << "Abhay is " ;
cout << obj.age << " years old.";
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In this program, We passed the value from main function to class and returning it to the main and then printing it.
- What is the output of this program?
#include <iostream>
using namespace std;
struct N
{
private:
int p, q, s;
public:
int fun1();
void fun2();
};
int N :: fun1()
{
return p + q + s;
}
void N :: fun2()
{
p = q = s = 0;
}
class M
{
int p, q, s;
public:
int fun1();
void fun2();
};
int M :: fun1()
{
return p + q + s;
}
void M :: fun2()
{
p = q = s = 0;
}
int main()
{
N obj1;
M obj2;
obj1.fun1();
obj1.fun2();
obj2.fun1();
obj2.fun2();
cout << "Identical results...";
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In this program, We apply the access specifiers to both the class and the structure.