https://res.cloudinary.com/hg6hswtwo/image/upload/v1/media/pics/oop_toolsandjobs_se2jyx_lttmtr
secondyear

Virtual Functions MCQs in Object Oriented Programming Part 1





Virtual Functions MCQs in Object Oriented Programming Part 1. This set of mcqs contains Virtual Functions in oop for competitive exams, SPPU online exams 2020.

1 What does the following statement mean?
int (*fp)(char*)
A pointer to a pointer
B pointer to an array of chars
C pointer to function taking a char* argument and returns an int
D function taking a char* argument and returning a pointer to int

Answer C

2 The operator used for dereferencing or indirection is ____
A *
B &
C ->
D –>>

Answer A

3 Choose the right option
 string* x, y;
A x is a pointer to a string, y is a string
B y is a pointer to a string, x is a string
C both x and y are pointer to string types
D none of the mentioned

Answer A

4 Which one of the following is not a possible state for a pointer?
A hold the address of the specific object
B point one past the end of an object
C Zero
D point to a byte

Answer D

5 Which of the following is illegal?
A int *ip;
B string s, *sp = 0;
C int i; double* dp = &i;
D int *pi = 0;

Answer D

6 #include <iostream>
 using namespace std;
 int main()
 {
 int a = 5, b = 10, c = 15;
 int *arr[ ] = {&a, &b, &c};
 cout <<arr[1];
 return 0;
 }
A 10
B 15
C 20
D Random number

Answer D

7 The correct statement for a function that takes pointer to a float, a pointer to a pointer to a
char and returns a pointer to a pointer to a integer is
A int **fun(float**, char**)
B int *fun(float*, char*)
C int ***fun(float*, char**)
D int ***fun(*float, **char)

Answer C

8 #include <iostream>
 using namespace std;
 int main()
 {
 char arr[20];
 int i;
 for(i = 0; i < 10; i++)
 *(arr + i) = 65 + i;
 *(arr + i) = '\0';
 cout << arr;
 return(0);
 }
A ABCDEFGHIJ
B AAAAAAAAA
C JJJJJJJJJJJJ
D None

Answer A
 
9 #include <iostream>
 using namespace std;
 int main()
 {
 char *ptr;
 char Str[] = "abcdefg";
 ptr = Str;
 ptr += 5;
 cout << ptr;
 return 0;
 }
A fg
B cdef
C defg
D abcd

Answer A

10 Which rule will not affect the friend function?
A private and protected members of a class cannot be accessed from outside
B private and protected member can be accessed anywhere
C both a &b
D None

Answer A

11 Which keyword is used to declare the friend function?
A Firend
B friend
C Classfriend
D myfriend

Answer B

12 #include <iostream>
 using namespace std;
 class Box
 {
 double width;
 public:
 friend void printWidth( Box box );
 void setWidth( double wid );
 };
 void Box::setWidth( double wid )
 {
 width = wid;
 }
 void printWidth( Box box )
 {
 box.width = box.width * 2;
 cout << "Width of box : " << box.width << endl;
 }
 int main( )
 {
 Box box;
 box.setWidth(10.0);
 printWidth( box );
 return 0;
 }
A 40
B 5
C 10
D 20

Answer D

13 Pick out the correct statement.
A A friend function may be a member of another class.
B A friend function may not be a member of another class.
C A friend function may or may not be a member of another class.
D None of the mentioned

Answer C

14 Where does keyword „friend‟ should be placed?
A function declaration
B function definition
C main function
D None

Answer A

15 #include <iostream>
 using namespace std;
 class sample
 {
 private:
 int a, b;
 public:
 void test()
 {
 a = 100;
 b = 200;
 }
 friend int compute(sample e1);
 };
 int compute(sample e1)
 {
 return int(e1.a + e1.b) - 5;
 }
 int main()
 {
 sample e;
 e.test();
 cout << compute(e);
 return 0;
 }
A 100
B 200
C 300
D 295

Answer D

16 #include <iostream>
 using namespace std;
 class base
 {
 int val1, val2;
 public:
 int get()
{
 val1 = 100;
 val2 = 300;
}
 friend float mean(base ob);
 };
 float mean(base ob)
 {
 return float(ob.val1 + ob.val2) / 2;
 }
 int main()
 {
 base obj;
 obj.get();
 cout << mean(obj);
 return 0;
 }
A 200
B 150
C 100
D 300

Answer A

17 To which does the function pointer point to?
A Variable
B Constants
C Function
D absolute variables

Answer C

18 What we will not do with function pointers?
A allocation of memory
B de-allocation of memory
C both a &b
D None

Answer C

19 #include <iostream>
 using namespace std;
 int add(int first, int second)
 {
 return first + second + 15;
 }
 int operation(int first, int second, int (*functocall)(int, int))
 {
 return (*functocall)(first, second);
 }
 int main()
 {
 int a;
 int (*plus)(int, int) = add;
 a = operation(15, 10, plus);
 cout << a;
 return 0;
 }
A 25
B 36
C 40
D 45

Answer C

20 #include <iostream>
 using namespace std;
 void func(int x)
 {
 cout << x ;
 }
 int main()
 {
 void (*n)(int);
 n = &func;
 (*n)( 2 );
 n( 2 );
 return 0;
 }
A 2
B 21
C 22
D 20

Answer C

21 #include <iostream>
 using namespace std;
 int n(char, int);
 int (*p) (char, int) = n;
 int main()
 {
 (*p)('d', 9);
 p(10, 9);
 return 0;
 }
 int n(char c, int i)
 {
 cout << c << i;
 return 0;
 }
A d9
9
B d9d9
C d9
D Compile time error

Answer A

22 #include <iostream>
 using namespace std;
 int func (int a, int b)
 {
 cout << a;
 cout << b;
 return 0;
 }
 int main(void)
 {
 int(*ptr)(char, int);
 ptr = func;
 func(2, 3);
 ptr(2, 3);
 return 0;
 }
A 2323
B 232
C 23
D Compile time error

Answer D

23 What are the mandatory part to present in function pointers?
A &
B return values
C Data types
D None

Answer C

24 What is meaning of following declaration?
int(*ptr[5])();
A ptr is pointer to function.
B ptr is array of pointer to function.
C ptr is pointer to such function which return type is array.
D ptr is pointer to array of function.

Answer B

25 What is size of generic pointer in c?
A 0
B 1
C 2
D Null

Answer C

26 Void pointer can point to which type of objects?
A Int
B Float
C Double
D All

Answer D

27 What does the following statement mean?
int (*fp)(char*)
A pointer to a pointer
B pointer to an array of chars
C pointer to function taking a char* argument and returns an int
D function taking a char* argument and returning a pointer to int

Answer C

28 What is size of generic pointer in C++ (in 32-bit platform) ?
A 2
B 4
C 8
D 0

Answer B

29 #include <iostream>
 using namespace std;
 int main()
 {
 int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
 cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
 return 0;
 }
A 15 18 21
B 21 21 21
C 24 24 24
D Compile time error

Answer B

30 #include <iostream>
 using namespace std;
 int main()
 {
 int i;
 char *arr[] = {"C", "C++", "Java", "VBA"};
 char *(*ptr)[4] = &arr;
 cout << ++(*ptr)[2];
 return 0;
 }
A ava
B java
C c++
D Compile time error

Answer A

Click here For Part-2





Publish Your Great Work

Touch below

Your AD here