C++ Test Questions Set 1

1)   Which of the following is not used to seek a file pointer?

a. ios::cur
b. ios::set
c. ios::end
d. ios::beg
Answer  Explanation 

ANSWER: ios::set

Explanation:
No explanation is available for this question!


2)   During dynamic memory allocation in CPP, new operator returns _________ value if memory allocation is unsuccessful.


a. False
b. NULL
c. Zero
d. None of these
Answer  Explanation 

ANSWER: NULL

Explanation:
No explanation is available for this question!


3)   We can create objects of the abstract class.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


4)   Which of the followings is/are pointer-to-member declarator?

a. ->*
b. .*
c. ::*
d. both a and b
Answer  Explanation 

ANSWER: ::*

Explanation:
No explanation is available for this question!


5)   Default value of static variable is_____ .

a. 0
b. 1
c. Garbage value
d. Compiler dependent
Answer  Explanation 

ANSWER: 0

Explanation:
No explanation is available for this question!


6)    ________ are used to format the data display in CPP.

a. Iterators
b. Punctuators
c. Manipulators
d. Allocators
Answer  Explanation 

ANSWER: Manipulators

Explanation:
No explanation is available for this question!


7)   Reusability of the code can be achieved in CPP through ______ .

a. Polymorphism
b. Encapsulation
c. Inheritance
d. Both a and c
Answer  Explanation 

ANSWER: Inheritance

Explanation:
No explanation is available for this question!


8)   By default, members of the class are ____________ in nature.

a. protected
b. private
c. public
d. static
Answer  Explanation 

ANSWER: private

Explanation:
No explanation is available for this question!


9)   class TEST
{
private:
int roll_no;
public:
int age;
char name[20];
private:
int grade;
protected:
char gender[20];
private:

private:
int m1, m2, m3;
};

In general view, is this class definition valid?


a. Yes
b. No


Answer  Explanation 

ANSWER: Yes

Explanation:
No explanation is available for this question!


10)   Which of the following is CPP style type-casting?

a. per = total/(float)m
b. per = total/float(m)
c. per = (float)total/m
d. None of these
Answer  Explanation 

ANSWER: per = total/float(m)

Explanation:
No explanation is available for this question!


11)   If a program uses Inline Function, then the function is expanded inline at ___________.

a. Compile time
b. Run time
c. Both a and b
d. None of these
Answer  Explanation 

ANSWER: Run time

Explanation:
No explanation is available for this question!


12)   In CPP, the size of the character array should be one larger than the number of characters in the string.


a. True
b. False


Answer  Explanation 

ANSWER: True

Explanation:
No explanation is available for this question!


13)   Which of the following is/are valid ways to allocate memory for an integer by dynamic memory allocation in CPP?

a. int *p = new int(100);
b. int *p; p = new int; *p = 100;
c. int *p = NULL; p = new int; *p=100;
d. Only 1,2
e. All of these
Answer  Explanation 

ANSWER: All of these

Explanation:
No explanation is available for this question!


14)   Which of the following is the perfect set of operators that can’t be overloaded in CPP ?

a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()
c. :: , . , .* , ?:
d. :: , ->, * , new, delete
Answer  Explanation 

ANSWER: :: , . , .* , ?:

Explanation:
No explanation is available for this question!


15)   Static variable in a class is initialized when _____ .

a. every object of the class is created.
b. last object of the class is created.
c. first object of the class is created.
d. No need to initialize static variable.
Answer  Explanation 

ANSWER: first object of the class is created.

Explanation:
No explanation is available for this question!


16)   To perform File I/O operations, we must use _____________ header file.

a. < ifstream>
b. < ofstream>
c. < fstream>
d. Any of these
Answer  Explanation 

ANSWER: < fstream>

Explanation:
No explanation is available for this question!


17)   An exception is thrown using _____________ keyword in CPP.

a. throws
b. throw
c. threw
d. Thrown
Answer  Explanation 

ANSWER: throw

Explanation:
No explanation is available for this question!


18)   Which of the followings is/are not a manipulator/s ?

1. flush
2. base
3. ends
4. oct
5. bin
6. skipws


a. Only 1, 6
b. Only 1,4,6
c. Only 1,3,6
d. Only 2,5
Answer  Explanation 

ANSWER: Only 2,5

Explanation:
No explanation is available for this question!


19)   If default constructor is not defined, then how the objects of the class will be created?

a. The compiler will generate error
b. Error will occur at run-time.
c. Compiler provides its default constructor to build the object.
d. None of these
Answer  Explanation 

ANSWER: Compiler provides its default constructor to build the object.

Explanation:
No explanation is available for this question!


20)   Is it mandatory to invoke/call a constructor for creating an object?

a. Yes
b. No


Answer  Explanation 

ANSWER: Yes

Explanation:
No explanation is available for this question!


21)   Members of the class can be declared with auto, extern or register storage classes.

a. True
b. False


Answer  Explanation 

ANSWER: False

Explanation:
No explanation is available for this question!


22)   C structure differs from CPP class in regards that by default all the members of the structure are __________ in nature.

a. private
b. protected
c. public
d. None of these
Answer  Explanation 

ANSWER: public

Explanation:
No explanation is available for this question!


23)   Which of the following best defines the syntax for template function ?

a. Template
b. Template return_type Function_Name(Parameters)
c. Both a and b
d. None of these
Answer  Explanation 

ANSWER: Both a and b

Explanation:
No explanation is available for this question!


24)   Generic pointers can be declared with__________ .

a. auto
b. void
c. asm
d. None of these
Answer  Explanation 

ANSWER: void

Explanation:
No explanation is available for this question!


25)   Which of the followings are true about constructors?

1. A class can have more than one constructor.
2. They can be inherited.
3. Their address can be referred.
4. Constructors cannot be declared in protected section of the class.
5. Constructors cannot return values.


a. Only 1,2,4
b. 1,2,4,5
c. 1,3,5
d. 1,4,5
Answer  Explanation 

ANSWER: 1,4,5

Explanation:
No explanation is available for this question!