Pfmcqs

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

 What is std in C++?

 std is a standard class in C++


 std is a standard namespace in C++
 std is a standard header file in C++
 std is a standard file reading header in C++
 Which of the following is not a type of Constructor in C++?
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) Friend constructor
 What is virtual inheritance in C++?
a) C++ technique to enhance multiple inheritance
b) C++ technique to ensure that a private member of the base class can be accessed
somehow
c) C++ technique to avoid multiple inheritances of classes
d) C++ technique to avoid multiple copies of the base class into children/derived
class
 Which of the following is used to create an output stream?
 ofstream
 ifstream
 iostream
 Fsstream
 Which of the following approach is used by C++?
a) Left-right
b) Right-left
c) Bottom-up
d) Top-down

 Which of the following syntax can be used to use a member of a namespace without
including that namespace?
 namespace::member
 namespace->member
 namespace.member
 namespace~member
 What happens if the following C++ statement is compiled and executed?
 int*ptr =NULL;delete ptr;
 a) The program is not semantically correct
b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time
 What will be the output of the following C++ code?
 #include<iostream>usingnamespace std;int main (){

1

intcin;
 cin>>cin;
 cout<<"cin: "<<cin;
 return0;}
 a) Segmentation fault
b) Nothing is printed
c) Error
 Which of the following correctly declares an array in C++?
a) array{10};
b) array array[10];
c) int array;
d) int array[10];
 Which of the following is not used as a file opening mode?
 ios::trunc
 ios::binary
 ios::in
 ios::ate

 Pick the incorrect statement about Character-Array.


 Character-Array can be terminated by a null character(‘\0’)
 Character-Array has a static size
 Character-Array has a dynamic size
 Character-Array has a threat of array-decay
 What will be the output of the following C++ code?
 #include <iostream> #include <string>usingnamespace std;int main(int argc,
charconst*argv[]){
 char s1[6]="Hello";
 char s2[6]="World";
 char s3[12]= s1 +""+ s2;
 cout<<s3;
 return0;}
 a) Hello
b) World
c) Error
d) Hello World

 What is the use of the indentation in c++?


 r distinguishes between comments and inner data
 distinguishes between comments and outer data
 distinguishes between comments and code
 r distinguishes between comments and outer data
 What happens if the following program is executed in C and C++?

2

#include <stdio.h>int main(void){
 intnew=5;
 printf("%d", new);}
 a) Error in C and successful execution in C++
b) Error in both C and C++
c) Error in C++ and successful execution in C
d) A successful run in both C and C

 Which is more effective while calling the C++ functions?


 call by object
 call by pointer
 call by value
 call by reference

 Which of the following is used to terminate the function declaration in C++?


 ;
 ]
 )
 :

 Which of the following type is provided by C++ but not C?


 double
 float
 int
 bool

 Which keyword is used to define the macros in c++?


 #macro
 #define
 macro
 define

 What is the difference between delete and delete[] in C++?


 delete is syntactically correct but delete[] is wrong and hence will give an error
if used in any case
 delete is used to delete normal objects whereas delete[] is used to pointer
objects
 delete is a keyword whereas delete[] is an identifier
 delete is used to delete single object whereas delete[] is used to
multiple(array/pointer of) objects

 Which is a true statement for object of String class?


 Object are immutable
 Object are mutable
 Object are created only once

3
 Object
can’t be created

 Which header file is used to include the string object functions in C++?
 #include <string.h>
 #include <cstring>
 #include <string>
 #include <string.cpp>

 Which of the following is not a modifier function in string class?


 operator+=()
 operator[]()
 push_back()
 erase()

 Which of the following is the default mode of the opening using the ofstream
class?
 ios::in
 b) ios::out
 c) ios::app
 d) ios::trunc
 Which of the following user-defined header file extension used in c++?
a) hg
b) cpp
c) h
d) hf

1. Which of the following is correct about remove_extent() function?


a. Removes the given dimension from an array
b. Removes the first dimension from the right of the array
c. Removes the first dimension from the left of the array
d. Removes the last dimension from the left of the array

2. Which keyword is used to define the macros in c++?


a. #macro
b. #define
c. macro
d. define

3. What is the difference between delete and delete[] in C++?


a. delete is syntactically correct but delete[] is wrong and hence will give
an error if used in any case
b. delete is used to delete normal objects whereas delete[] is used to
pointer objects
c. delete is a keyword whereas delete[] is an identifier
d. delete is used to delete single object whereas delete[] is used to
multiple(array/pointer of) objects

4
4. Which is a true statement for object of String class?
a. Object are immutable
b. Object are mutable
c. Object are created only once
d. Object can’t be created

5. Which of the following is not used to seek file pointer?


a. ios::set
b. ios::end
c. ios::cur
d. ios::beg
Which of the following is correct about this pointer in C++?
a) this pointer is passed as a hidden argument in all static variables of
a class
b) this pointer is passed as a hidden argument in all the functions of a
class
c) this pointer is passed as a hidden argument in all non-static
functions of a class
d) this pointer is passed as a hidden argument in all static functions of
a class

6. What is the use of rank() function in C++?


a. Returns size of each dimension
b. Returns how many total elements can be stored in an array
c. Returns how many elements are in array currently
d. Returns the dimension of an array

7. What is string objects in C++?


a. Stream of alphabets
b. A stream of well-defined characters
c. Stream of characters
d. A stream of characters terminated by \0

8. Which function is used in C++ to get the current position of file pointer in a file?
a. tell_p()
b. get_pos()
c. get_p()
d. tell_pos()

9. Which of the header file is used for array type manipulation?


a. <array>
b. <type_traits>
c. <iostream>
d. std namespace

10. Which of the following is correct about dynamic polymorphism?


a. In dynamic polymorphism, the conflict between the function call is
resolved during the compile time

5
b. In dynamic polymorphism, the conflict between the function call is
resolved during the run time
c. In dynamic polymorphism, the conflict between the function call is never
resolved during the execution of the program
d. In dynamic polymorphism, the conflict between the function call is
resolved at the beginning of the program

11. What is the use of is_same() function in C++?


a. To check if a variable is array type or not
b. To check whether two variables have the same characteristics
c. To check if two variable is of array type or not
d. To check whether two variables are different or not

12. How many types of polymorphism are there?


a. 1
b. 2
c. 3
d. 4
What will be the output of the following C++ function?

1.
int main()

2.
3.
{

4.
5.
registerint i =1;

6.
7.
int*ptr =&i;

8.
9.
cout<<*ptr;

10.
11.
return0;

12.
13.
}

14.
a) Runtime error may be possible
b) Compiler error may be possible
c) 1
d) 0

6
13. Which
of the following operator is used with this pointer to access members of a
class?
a. .
b. !
c. ->
d. ~

7
8

You might also like