Select Page
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

# Multiple choice question for engineering

## Set 1

1. Which operator is having right to left associativity in the following?
a) Array subscripting
b) Function call
d) Type cast

2. Which operator is having the highest precedence?
a) postfix
b) unary
c) shift
d) equality

Answer: a [Reason:] The operator which is having highest precedence is postfix and lowest is equality.

3. What is this operator called ?: ?
a) conditional
b) relational
c) casting operator
d) none of the mentioned

Answer: a [Reason:] In this operator, if the condition is true means, it will return the first operator, otherwise second operator.

4. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int main()`
4. `    {`
5. `        int a;`
6. `        a = 5 + 3 * 5;`
7. `        cout << a;`
8. `        return 0;`
9. `    }`

a) 35
b) 20
c) 25
d) 30

Answer: b [Reason:] Because the * operator is having highest precedence, So it is executed first and then the + operator will be executed. Output: \$ g++ op1.cpp \$ a.out 20

5. What is the use of dynamic_cast operator?
a) it converts virtual base class to derived class
b) it converts virtual base object to derived objeccts
c) it will convert the operator based on precedence
d) none of the mentioned

Answer: a [Reason:] Because the dynamic_cast operator is used to convert from base class to derived class.

6. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int main()`
4. `    {`
5. `        int a = 5, b = 6, c, d;`
6. `        c = a, b;`
7. `        d = (a, b);`
8. `        cout << c << ' ' << d;`
9. `        return 0;`
10. `    }`

a) 5 6
b) 6 5
c) 6 7
d) none of the mentioned

Answer: a [Reason:] It is a separtor here.In c,the value a is stored in c and in d the value b is stored in d because of the bracket. Output: \$ g++ op3.cpp \$ a.out 5 6

7. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int main()`
4. `    {`
5. `        int i, j;`
6. `        j = 10;`
7. `        i = (j++, j + 100, 999 + j);`
8. `        cout << i;`
9. `        return 0;`
10. `    }`

a) 1000
b) 11
c) 1010
d) 1001

Answer: c [Reason:] j starts with the value 10. j is then incremented to 11. Next, j is added to 100. Finally, j (still containing 11) is added to 999 which yields the result 1010. Output: \$ g++ op2.cpp \$ a.out 1010

8. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int main ()`
4. `    {`
5. `        int x, y;`
6. `        x = 5;`
7. `        y = ++x * ++x;`
8. `        cout << x << y;`
9. `        x = 5;`
10. `        y = x++ * ++x;`
11. `        cout << x << y;`
12. `        return 0;`
13. `    }`

a) 749736
b) 736749
c) 367497
d) none of the mentioned

Answer: a [Reason:] Because of the precedence the pre-increment and post increment operator, we got the output as 749736. Output: \$ g++ op.cpp \$ a.out 749736

9. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int main()`
4. `    {`
5. `        int a = 5, b = 6, c;`
6. `        c = (a > b) ? a : b;`
7. `        cout << c;`
8. `        return 0;`
9. `    }`

a) 6
b) 5
c) 4
d) 7

Answer: a [Reason:] Here the condition is false on conditional operator, so the b value is assigned to c. Output: \$ g++ op1.cpp \$ a.out 6

10. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    main()`
4. `    {`
5. `        double a = 21.09399;`
6. `        float b = 10.20;`
7. `        int c ,d;`
8. `        c = (int) a;`
9. `        d = (int) b;`
10. `        cout << c <<' '<< d;`
11. `        return 0;`
12. `    }`

a) 20 10
b) 10 21
c) 21 10
d) none of the mentioned

Answer: c [Reason:] In this program, we are casting the operator to integer, So it is printing as 21 and 10. Output: \$ g++ op5.cpp \$ a.out 21 10

## Set 2

a) type
b) number of arguments
c) type & number of arguments
d) none of the mentioned

2. In which of the following we cannot overload the function?
a) return function
b) caller
c) called function
d) none of the mentioned

d) none of the mentioned

4. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    void print(int i)`
4. `    {`
5. `        cout << i;`
6. `    }`
7. `    void print(double  f)`
8. `    {`
9. `        cout << f;`
10. `    }`
11. `    int main(void)`
12. `    {`
13. `        print(5);`
14. `        print(500.263);`
15. `        return 0;`
16. `    }`

a) 5500.263
b) 500.2635
c) 500.263
d) none of the mentioned

Answer: a [Reason:] In this program, we are printing the values and the values will be print(5) will be printed first because of the order of the execution. Output: \$ g++ over.cpp \$ a.out 5500.263

5. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int Add(int X, int Y, int Z)`
4. `    {`
5. `        return X + Y;`
6. `    }`
7. `    double Add(double X, double Y, double Z)`
8. `    {`
9. `        return X + Y;`
10. `    }`
11. `    int main()`
12. `    {`
13. `        cout << Add(5, 6);`
14. `        cout << Add(5.5, 6.6);`
15. `        return 0;`
16. `    }`

a) 11 12.1
b) 12.1 11
c) 11 12
d) compile time error

6. What is the output of the following program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int operate (int a, int b)`
4. `    {`
5. `        return (a * b);`
6. `    }`
7. `    float operate (float a, float b)`
8. `    {`
9. `        return (a / b);`
10. `    }`
11. `    int main()`
12. `    {`
13. `        int x = 5, y = 2;`
14. `        float n = 5.0, m = 2.0;`
15. `        cout << operate(x, y) <<"t";`
16. `        cout << operate (n, m);`
17. `        return 0;`
18. `    }`

a) 10.0 5.0
b) 5.0 2.5
c) 10.0 5
d) 10 2.5

Answer: d [Reason:] In this program, we are divide and multiply the values. Output: \$ g++ over3.cpp \$ a.out 10 2.5

a) Very long functions that can hardly run
b) One function containing another one or more functions inside it
c) Two or more functions with the same name but different number of parameters or type
d) None of the mentioned

8. What will happen while using pass by reference
a) The values of those variables are passed to the function so that it can manipulate them
b) The location of variable in memory is passed to the function so that it can use the same memory area for its processing
c) The function declaration should contain ampersand (& in its type declaration)
d) All of the mentioned

Answer: b [Reason:] In pass by reference, we can use the function to access the variable and it can modify it. Therefore we are using pass by reference.

9. When our function doesn’t need to return anything means what will we use/send as parameter in function?
a) void
b) blank space
c) both void & blank space
d) none of the mentioned

10. What are the advantages of passing arguments by reference?
a) Changes to parameter values within the function also affect the original arguments.
b) There is need to copy parameter values (i.e. less memory used)
c) There is no need to call constructors for parameters (i.e. faster)
d) All of the mentioned

## Set 3

1. What is meaning of following declaration?
int(*p[5])();
a) p is pointer to function
b) p is array of pointer to function
c) p is pointer to such function which return type is array
d) p is pointer to array of function

Answer: b [Reason:] In the above declaration the variable p is array not pointer.

2. What is size of generic pointer in C++ (in 32-bit platform) ?
a) 2
b) 4
c) 8
d) 0

Answer: b [Reason:] Size of any type of pointer is 4 bytes in 32-bit platforms.

3. What is the output of this program?

1. `   #include <iostream>`
2. `   using namespace std;`
3. `   int main()`
4. `   {`
5. `       int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};`
6. `       cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];`
7. `       return 0;`
8. `   }`

a) 15 18 21
b) 21 21 21
c) 24 24 24
d) Compile time error

Answer: b [Reason:] a[1][2] means 1 * (4)+2 = 6th element of an array staring from zero. Output: \$ g++ point.cpp \$ a.out 21 21 21

4. What is the output of this program?

1. `   #include <iostream>`
2. `   using namespace std;`
3. `   int main()`
4. `   {`
5. `       int i;`
6. `       char *arr[] = {"C", "C++", "Java", "VBA"};`
7. `       char *(*ptr)[4] = &arr;`
8. `       cout << ++(*ptr)[2];`
9. `       return 0;`
10. `   }`

a) ava
b) java
c) c++
d) compile time error

Answer: a [Reason:] In this program we are moving the pointer from first position to second position and printing the remaining value. Output: \$ g++ point1.cpp \$ a.out ava

5. What is the output of this program?

1. `   #include <iostream>`
2. `   using namespace std;`
3. `   int main()`
4. `   {`
5. `       int arr[] = {4, 5, 6, 7};`
6. `       int *p = (arr + 1);`
7. `       cout << *p;`
8. `       return 0;`
9. `   }`

a) 4
b) 5
c) 6
d) 7

Answer: b [Reason:] In this program, we are making the pointer point to next value and printing it. \$ g++ point3.cpp \$ a.out 5

6. What is the output of this program?

1. `   #include <iostream>`
2. `   using namespace std;`
3. `   int main()`
4. `   {`
5. `       int arr[] = {4, 5, 6, 7};`
6. `       int *p = (arr + 1);`
7. `       cout << arr;`
8. `       return 0;`
9. `   }`

a) 4
b) 5
d) 7

Answer: c [Reason:] As we couted to print only arr, it will print the address of the array. Output: \$ g++ point2.cpp \$ a.out 0xbfb1cff

7. What is the output of this program?

1. `   #include <iostream>`
2. `   using namespace std;`
3. `   int main ()`
4. `   {`
5. `       int numbers[5];`
6. `       int * p;`
7. `       p = numbers;  *p = 10;`
8. `       p++;  *p = 20;`
9. `       p = &numbers[2];  *p = 30;`
10. `       p = numbers + 3;  *p = 40;`
11. `       p = numbers;  *(p + 4) = 50;`
12. `       for (int n = 0; n < 5; n++)`
13. `           cout << numbers[n] << ",";`
14. `       return 0;`
15. `   }`

a) 10,20,30,40,50,
b) 1020304050
c) compile error
d) runtime error

Answer: a [Reason:] In this program, we are just assigning a value to the array and printing it and immediately dereferencing it. Output: \$ g++ point4.cpp \$ a.out 10,20,30,40,50,

8. What is the output of this program?

1. `   #include <iostream>`
2. `   using namespace std;`
3. `   int main()`
4. `   {`
5. `        int arr[] = {4, 5, 6, 7};`
6. `        int *p = (arr + 1);`
7. `        cout << *arr + 9;`
8. `        return 0;`
9. `   }`

a) 12
b) 5
c) 13
d) error

Answer: c [Reason:] In this program, we are adding the value 9 to the initial value of the array, So it’s printing as 13. Output: \$ g++ point5.cpp \$ a.out 13

## Set 4

1. Which of the following will not return a value?
a) null
b) void
c) empty
d) free

2. ____ have the return type void?
a) all functions
b) constructors
c) destructors
d) none of the mentioned

Answer: d [Reason:] Constructor creats an Object and Destructor destroys the object. They are not supposed to return anything, not even void.

3. What does the following statement mean?
void a;
a) variable a is of type void
b) a is an object of type void
c) declares a variable with value a
d) flags an error

Answer: d [Reason:] There are no void objects.

4. Choose the incorrect option
a) void is used when the function does not return a value
b) void is also used when the value of a pointer is null
c) void is used as the base type for pointers to objects of unknown type
d) void is a special fundamental type

Answer: b [Reason:] void fundamental type is used in the cases of a and c.

5. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    int main()`
4. `    {`
5. `        void a = 10, b = 10;`
6. `        int c;`
7. `        c = a + b;`
8. `        cout << c;`
9. `        return 0;`
10. `    }`

a) 20
b) compile time error
c) runtime error
d) none of the mentioned

Answer: b [Reason:] void will not accept any values to its type.

## Set 5

1. How many kinds of classes are there in c++?
a) 1
b) 2
c) 3
d) 4

Answer: b [Reason:] There are two kinds of classes in c++. They are absolute class and concrete class.

2. What is meant by polymorphism?
a) class having many forms
b) class having only single form
c) class having two forms
d) none of the mentioned

Answer: a [Reason:] Polymirphism is literally means class having many forms.

3. How many types of inheritance are there in c++?
a) 2
b) 3
c) 4
d) 5

Answer: d [Reason:] There are five types of inheritance in c++. They are single, Multiple, Hierarchical, Multilevel, Hybrid.

4. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    class stu`
4. `    {`
5. `        protected:`
6. `        int rno;`
7. `        public:`
8. `        void get_no(int a)`
9. `        {`
10. `            rno = a;`
11. `        }`
12. `        void put_no(void)`
13. `        {`
14. `        }`
15. `    };`
16. `    class test:public stu`
17. `    {`
18. `        protected:`
19. `        float part1,part2;`
20. `        public:`
21. `        void get_mark(float x, float y)`
22. `        {`
23. `            part1 = x;`
24. `            part2 = y;`
25. `        }`
26. `        void put_marks()`
27. `        {`
28. `        }`
29. `    };`
30. `    class sports`
31. `    {`
32. `        protected:`
33. `        float score;`
34. `        public:`
35. `        void getscore(float s)`
36. `        {`
37. `            score = s;`
38. `        }`
39. `        void putscore(void)`
40. `        {`
41. `        }`
42. `    };`
43. `    class result: public test, public sports`
44. `    {`
45. `        float total;`
46. `        public:`
47. `        void display(void);`
48. `    };`
49. `    void result::display(void)`
50. `    {`
51. `        total = part1 + part2 + score;`
52. `        put_no();`
53. `        put_marks();`
54. `        putscore();`
55. `        cout << "Total Score=" << total << "n";`
56. `    }`
57. `    int main()`
58. `    {`
59. `        result stu;`
60. `        stu.get_no(123);`
61. `        stu.get_mark(27.5, 33.0);`
62. `        stu.getscore(6.0);`
63. `        stu.display();`
64. `        return 0;`
65. `    }`

a) 66.5
b) 64.5
c) 62.5
d) 60.5

Answer: a [Reason:] In this program, We are passing the values by using different methods and totaling the marks to get the result. Output: \$ g++ class.cpp \$ a.out Total Score=66.5

5. What is the output of this program?

1. `    #include <iostream>`
2. `    using namespace std;`
3. `    class poly`
4. `    {`
5. `        protected:`
6. `        int width, height;`
7. `        public:`
8. `        void set_values(int a, int b)`
9. `        {`
10. `            width = a; height = b;`
11. `        }`
12. `    };`
13. `    class Coutput`
14. `    {`
15. `        public:`
16. `        void output(int i);`
17. `    };`
18. `    void Coutput::output(int i)`
19. `    {`
20. `        cout << i;`
21. `    }`
22. `    class rect:public poly, public Coutput`
23. `    {`
24. `        public:`
25. `        int area()`
26. `        {`
27. `            return(width * height);`
28. `        }`
29. `    };`
30. `    class tri:public poly, public Coutput`
31. `    {`
32. `        public:`
33. `        int area()`
34. `        {`
35. `            return(width * height / 2);`
36. `        }`
37. `    };`
38. `    int main()`
39. `    {`
40. `        rect rect;`
41. `        tri trgl;`
42. `        rect.set_values(3, 4);`
43. `        trgl.set_values(4, 5);`
44. `        rect.output(rect.area());`
45. `        trgl.output(trgl.area());`
46. `        return 0;`
47. `    }`

a) 1212
b) 1210
c) 1010
d) none of the mentioned

Answer: b [Reason:] In this program, We are calculating the area of rectangle and triangle by using multilevel inheritance. \$ g++ class1.cpp \$ a.out 1210

6. What is meant by containership?
a) class contains objects of other class types as its members
b) class contains objects of other class types as its objects
c) class contains objects of other class types as its members 7 also objects
d) none of the mentioned

7. How many types of constructor are there in C++?
a) 1
b) 2
c) 3
d) 4

Answer: c [Reason:] There are three types of constructor in C++. They are Default constructor, Parameterized constructor, Copy constructor.

8. How many constructors can present in a class?
a) 1
b) 2
c) 3
d) multiple

Answer: d [Reason:] There can be multiple constructors of the same class, provided they have different signatures.

9. What should be the name of constructor?
a) same as object
b) same as member
c) same as class
d) none of the mentioned