Reliance Jio C++ Programming Quiz-1

Question 1

Time: 00:00:00
Which of the followings is/are automatically added to every class, if we do not write our own.

Copy Constructor

Copy Constructor

Assignment Operator

Assignment Operator

A constructor without any parameter

A constructor without any parameter

All of the above

All of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
What is the difference between struct and class in C++?

All members of a structure are public and structures don't have constructors and destructors

All members of a structure are public and structures don't have constructors and destructors

All members of a structure are public and structures don't have virtual functions

All members of a structure are public and structures don't have virtual functions

Members of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.

Members of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.

All of the above

All of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
Which of the following is true?

All objects of a class share all data members of class

All objects of a class share all data members of class

Objects of a class do not share non-static members. Every object has its own copy.

Objects of a class do not share non-static members. Every object has its own copy.

Objects of a class do not share codes of non-static methods, they have their own copy

Objects of a class do not share codes of non-static methods, they have their own copy

All of the above

All of the above

None of the above

None of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
Which of the following is true about inline functions and macros

Inline functions do type checking for parameters, macros don't

Inline functions do type checking for parameters, macros don't

Macros are processed by pre-processor and inline functions are processed in later stages of compilation.

Macros are processed by pre-processor and inline functions are processed in later stages of compilation.

Macros cannot have return statement, inline functions can.

Macros cannot have return statement, inline functions can.

Macros are prone to bugs and errors, inline functions are not.

Macros are prone to bugs and errors, inline functions are not.

All of the above

All of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
When a copy constructor may be called?

When an object of the class is returned by value.

When an object of the class is returned by value.

When an object is constructed based on another object of the same class

When an object is constructed based on another object of the same class

When an object of the class is passed (to a function) by value as an argument.

When an object of the class is passed (to a function) by value as an argument.

When compiler generates a temporary object.

When compiler generates a temporary object.

All of the above

All of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
Which of the following is not correct for virtual function in C++ ?

Must be declared in public section of class.

Must be declared in public section of class.

Virtual function can be static.

Virtual function can be static.

Virtual function should be accessed using pointers.

Virtual function should be accessed using pointers.

Virtual function is defined in base class.

Virtual function is defined in base class.

None of the above

None of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
Which of the following is not correct (in C++) ?

  1. Class templates and function templates are instantiated in the same way

  2. Class templates differ from function templates in the way they are initiated

  3. Class template is initiated by defining an object using the template argument

  4. Class templates are generally used for storage classes.

(1)

(1)

(2), (3), (4)

(2), (3), (4)

(2), (4)

(2), (4)

(4)

(4)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
Which of the following cannot be passed to a function in C++ ?

Structure

Structure

Constant

Constant

Array

Array

Header file

Header file

None of the above

None of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
Predict the output of following C++ program











#include<iostream>

using namespace std;




class Test

{

private:

  int x;

  int y;

public:

  Test(int x = 0, int y = 0) { this->x = x; this->y = y; }

  static void fun1() { cout << "Inside fun1()"; }

  static void fun2() { cout << "Inside fun2()"; this->fun1(); }

};




int main()

{

  Test obj;

  obj.fun2();

  return 0;

}



Inside fun2() Inside fun1()

Inside fun2() Inside fun1()

Inside fun2()

Inside fun2()

Inside fun1() Inside fun2()

Inside fun1() Inside fun2()

Compiler Error

Compiler Error

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
Which of the following is a correct statement?

Composition is a weak type of association between two classes with strong ownership.

Composition is a weak type of association between two classes with strong ownership.

Composition is a strong type of association between two classes with partial ownership.

Composition is a strong type of association between two classes with partial ownership.

Composition is a strong type of association between two classes with partial ownership.

Composition is a strong type of association between two classes with partial ownership.

Composition is a strong type of association between two classes with full ownership.

Composition is a strong type of association between two classes with full ownership.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 11

Time: 00:00:00
Assume that an integer takes 4 bytes and there is no alignment in following classes, predict the output.











#include<iostream>

using namespace std;




class base {

    int arr[10];

};




class b1: public base { };




class b2: public base { };




class derived: public b1, public b2 {};




int main(void)

{

  cout << sizeof(derived);

  return 0;

}



40

40

80

80

1

1

4

4

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 12

Time: 00:00:00
What should be put in a try block?
1. Statements that might cause exceptions

2. Statements that should be skipped in case of an exception

Only 1

Only 1

Only 2

Only 2

Both 1 and 2

Both 1 and 2

Neither 1 nor 2

Neither 1 nor 2

Either 1 or 2

Either 1 or 2

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 13

Time: 00:00:00
Which of the following is true about virtual functions in C++.

Virtual functions are functions that can be overridden in derived class with the same signature.

Virtual functions are functions that can be overridden in derived class with the same signature.

Virtual functions enable run-time polymorphism in a inheritance hierarchy.

Virtual functions enable run-time polymorphism in a inheritance hierarchy.

If a function is 'virtual' in the base class, the most-derived class's implementation of the function is called according to the actual type of the object referred to, regardless of the declared type of the pointer or reference. In non-virtual functions, the functions are called according to the type of reference or pointer.

If a function is 'virtual' in the base class, the most-derived class's implementation of the function is called according to the actual type of the object referred to, regardless of the declared type of the pointer or reference. In non-virtual functions, the functions are called according to the type of reference or pointer.

All of the above

All of the above

None of the above

None of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 14

Time: 00:00:00
Which of the following is true about exception handling in C++? 
1) There is a standard exception class like Exception class in Java.
2) All exceptions are unchecked in C++, i.e., compiler doesn't check if the exceptions are caught or not.
3) In C++, a function can specify the list of exceptions that it can throw using comma separated list like following.

void fun(int a, char b) throw (Exception1, Exception2, ..)

1 and 3

1 and 3

1, 2 and 3

1, 2 and 3

1 and 2

1 and 2

2 and 3

2 and 3

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 15

Time: 00:00:00
Which of the following operators should be preferred to overload as a global function rather than a member method?

Postfix ++

Postfix ++

Comparison Operator

Comparison Operator

Insertion Operator <<

Insertion Operator <<

Prefix++

Prefix++

None of the above

None of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 16

Time: 00:00:00
Predict the output of following C++ program.











#include<iostream>

using namespace std;




int &fun()

{

    static int x = 10;

    return x;

}

int main()

{

    fun() = 30;

    cout << fun();

    return 0;

}



Compiler Error: Function cannot be used as lvalue

Compiler Error: Function cannot be used as lvalue

10

10

30

30

20

20

None of the Above

None of the Above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 17

Time: 00:00:00
A member function can always access the data in __________ , (in C++).

the class of which it is member

the class of which it is member

the object of which it is a member

the object of which it is a member

the public part of its class

the public part of its class

the private part of its class

the private part of its class

None of the above

None of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 18

Time: 00:00:00
Which among following is used to open a file in binary mode ?

ios:app

ios:app

ios::out

ios::out

ios::in

ios::in

ios::binary

ios::binary

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 19

Time: 00:00:00
Which member function is used to determine whether the stream object is currently associated with a file?

is_open

is_open

buf

buf

string

string

none of the mentioned

none of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 20

Time: 00:00:00
Which header file is used for reading and writing to a file?

#include

#include

#include

#include

#include

#include

None of the mentioned

None of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Completed

0/0

Accuracy

0%