Download this pdf file containing multiple choice questions (MCQs) from C++ Programming language. The pdf file contains ten printed pages including the cover page and answer sheet. Each questions are listed at the beginning in two column format and correct answers are presented on the last page.
Subject: C++ Programming
Name: MCQ Bank C++ Programming Download.pdf
Size: 838 KB
No of Pages: 10 PP
An utmost care is taken while composing this eBook so that any unintentional mistakes are avoided. However, if you discover any error or mistakes, you are encouraged to contact and inform about it. Your queries and suggestions are highly appreciated.
Excerpt:
- If the class name is X, what is the type of its “this” pointer (in a nonstatic, non-const member function)?
- const X* const
- X* const
- X*
- X&
- Which classes allow primitive types to be accessed as objects?
- Storage
- Virtual
- Friend
- Wrapper
- When is std::bad_alloc exception thrown?
- When new operator cannot allocate memory
- When alloc function fails
- When type requested for new operation is considered bad, thisexception is thrown
- When delete operator cannot delete teh allocated (corrupted) object
- Which one of the following is not a fundamental data type in C++
- float
- string
- int
- wchar_t
- Which of the following is a valid destructor of the class name “Country”
- int ~Country()
- void Country()
- int ~Country(Country obj)
- void ~Country()
- Which of the following correctly describes C++ language?
- Statically typed language
- Dynamically typed language
- Both Statically and dynamically typed language
- Type-less language
- Which of the following keyword supports dynamic method resolution?
- abstract
- Virtual
- Dynamic
- Typeid
- Which of the following is the most preferred way of throwing and handling exceptions?
- Throw by value and catch by reference.
- Throw by reference and catch by reference.
- Throw by value and catch by value
- Throw the pointer value and provide catch for teh pointer type.
- Which of the following is not true about preprocessor directives
- They begin with a hash symbol
- They are processed by a preprocessor
- They form an integral part of the code
- They have to end with a semi colon
- What’s wrong? while( (i < 10) && (i > 24))
- the logical operator && cannot be used in a test condition
- the while loop is an exit-condition loop
- the test condition is always false
- the test condition is always true
- A continue statement causes execution to skip to
- the return 0; statement
- the first statement after the loop
- the statement following the continue statement
- the next iteration of the loop
- What’s wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);
- the question mark should be an equal sign
- the first semicolon should be a colon
- there are too many variables in the statement
- the conditional operator is only used with apstrings
- What’s wrong? for (int k = 2, k <=12, k++)
- the increment should always be ++k
- the variable must always be the letter i when using a for loop
- there should be a semicolon at the end of the statement
- the commas should be semicolons
- Which of the following is not recommended in a header file?
- Type definitions (typedefs)
- Class definitions
- Function definitions
- Template definitions
- Which of the STL containers store the elements contiguously (in adjecent memory locations)?
- std::vector
- std::list
- std::map
- std::set
- Which of the following is not a standard exception built in C++.
- std::bad_creat
- std::bad_alloc
- std::bad_cast
- std::bad_typeid
- What does STL stand for?
- Simple Template Library
- Standard Template Library
- Static Type Library
- Single Type-based Library
- What is the difference between overloaded functions and overridden functions?
- Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding
- Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called a overloaded fucntion.
- Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding
- Redefining a function in a friend class is called function overloading while Redefining a function in a derived class is called as overridden fucnion.
- Which one of the following is not a valid reserved keyword in C++
- Explicit
- Public
- Implicit
- Private
- Each pass through a loop is called a/an
- enumeration
- iteration
- culmination
- pass through
- Which of the following is true about const member functions?
- const members can be invoked on both const as well as nonconst objects
- const members can be invoked only on const objects and not on nonconst objects
- nonconst members can be invoked on const objects as well as nonconst objects
- none of the above
- Which of the following relationship is known as inheritancerelationship?
- ‘has-a’ relationship
- ‘is-a’ relationship
- association relationship
- none of the above
- If class A is friend of class B and if class B is friend of class C, which of the following is true?
- Class C is friend of class A
- Class A is friend of class C
- Class A and Class C do not have any friend relationship
- None of the above
- A direct access file is:
- A file in which recoreds are arranged in a way they are inserted in a file
- A file in which records are arranged in a particular order
- Files which are stored on a direct access storage medium
- None of the above
- Which of the following is not a component of file system
- Access method
- Auxiliary storage management
- Free integrity mechanism
- None of the above
- Seek time is
- time taken to retrieve a dta
- Time taken by read/write head mechanism to position itself over appropriate cylinder
- Time taken by appropriate sector to come under read/write
- None of the above
- ‘Prime area’ in context of file system is defined as
- It is memory area created by operating system
- It is an area into which data records are written
- It is the main area of a web page
- None of the above
- In mulit-list organization
- Records that have equivalent value for a given secondary index item are linked together to form a list.
- Records are loaded in ordered sequence defined by collating sequence by content of the key
- Records are directly accessed by record key field
- None of the above
- Which of the following is/are advantages of cellular partitioned structure:
- Simultaneous read operations can be overlapped
- Search time is reduced
- Both a & b
- None of the above
- *ptr++ is equivalenet to:
- ptr++
- *ptr
- ++*ptr
- None of the above
- The conditional compilation
- It is taken care of by the compiler
- It is setting the compiler option conditionally
- It is compiling a program based on a condition
- none of above
- Originally ‘C’ was developed as:
- System programming language
- General purpose language
- Data processing language
- None of above
- An inverted file
- Locates information about data in small files that are maintained apart from actual data record
- A file which stores opposite records
- A file which stores information about records of a system
- None of above
- Which of the following is not a file operation:
- Repositioning
- Truncating
- Appending
- None of above
- Latency time is:
- Time taken by read/write head mechanism to position itself over appropriate cylinder
- Time taken to transfer a dta from memory
- Time taken by appropriate sector to come under read/write head
- None of above
- The two types of file structure existing in VSAM file are
- Key sequenced structure, entry sequenced structure
- Key sequence structure, exit sequenced structure
- Entry sequence structure, exit sequenced structure
- None of above
- How many copies of a class static member are shared between objects of the class?
- A copy of the static member is shared by all objects of a class
- A copy is created only when at least one object is created from that class
- A copy of the static member is created for each instntiation of the class
- No memory is allocated for static members of a class
- Which looping process checks the test condition at the end of the loop?
- for
- while
- do-while
- no looping process checks the test condition at the end
- The default access level assigned to members of a class is ___________
- Private
- Public
- Protected
- Needs to be assigned
- Which of the following correctly describes the meaning of‘namespace’ feature in C++?
- Namespaces refer to the memory space allocated for names used in a program
- Namespaces refer to space between the names in a program
- Namespaces refer to packing structure of classes in a program.
- Namespaces provide facilities for organizing the names in aprogram to avoid name clashes.
- Which of the following correctly describes the meaning of ‘namespace’ feature in C++?
- Namespaces refer to the memory space allocated for names used in a program
- Namespaces refer to space between teh names in a program
- Namespaces refer to space between the names in a program
- namespaces provide facilities for organizing the names in a program to avoid name clashes
- Which of the following language is not supported by C++?
- Exception Handling
- Reflection
- Operator Overloading
- Namespaces
- class derived: public base1, public base2 { } is an example of
- Polymorphic inheritance
- Multilevel inheritance
- Hierarchical inheritance
- Multiple inheritance
- Which of the following languages is a subset of C++ language?
- C language
- Java Language
- C# language
- language
- How do we declare an ‘interface’ class?
- By making all the methods pure virtual in a class
- By making all the methods abstract using the keyword ‘abstract’ in a class
- By declaring the class as interface with the keyword ‘interface’
- It is not possible to create interface class in C++
- How do we declare an abstract class?
- By providing at least one pure virtual method (function signature followed by ==0;) in a class
- By declaring at least one method abstract using the keyword ‘abstract’ in a class
- By declaring the class abstract with the keyword ‘abstract’
- It is not possible to create abstract classes in C++
- Which of the following is not an advantage of secondary memory
- It is cost-effective
- It has large storage capacity
- It has highest speed
- It is easily portable
- What happens when a pointer is deleted twice?
- It can abort the program
- It can cause a failure
- It can cause an error
- It can cause a trap
- Which of the following language feature is not an access specifier in C++?
- public
- private
- C protected
- internal
- Expression C=i++ causes
- Value of i assigned to C and then i incremented by 1
- i to be incremented by 1 and then value of i assigned to C
- Value of i assigned to C
- i to be incremented by 1
- The statement i++; is equivalent to
- i = i + i;
- i = i + 1;
- i = i – 1;
- i –;
- In C language, a hexadecimal number is represented by writing
- x
- xo
- ox
- h
- Which of the following library function below by default aborts the program?
- Terminate()
- end()
- Abort()
- exit()
- If a member needs to have unique value for all the objects of that same class, declare the member as
- Global variable outside class
- Local variable inside constructor
- Static variable inside class
- Dynamic variable inside class
- Value of ix+j, if i,j are integer type and ix long type would be
- integer
- float
- long integer
- double percision
- Which of the following below can perform conversions between pointers to related classes?
- A. cast_static
- B. dynamic_cast
- c. static_cast
- D. cast_dynamic
- How do we define a constructor?
- a. x~() {}
- B. X() {}~
- C. X() ~{}
- D. ~X() {}
- Vtables
- creates a static table per class
- creates a static table per object
- creates a dynamic table per class
- creates a dynamic table per object
- When class B is inherited from class A, what is the order in which the constructers of those classes are called
- Class A first Class B next
- Class B first Class A next
- Class B’s only as it is the child class
- Class A’s only as it is the parent class
- Which of the following is the most general exception handler that catches exception of any type?
- catch(std::exception)
- catch(std::any_exception)
- catch(…)
- catch()
- Which of the following is the most general exception handler that catches exception of ‘any type’?
- catch(std::exception)
- catch(std::any_exception)
- catch(…)
- catch()
- In a group of nested loops, which loop is executed the most number of times?
- the outermost loop
- the innermost loop
- all loops are executed the same number of times
- cannot be determined without knowing the size of the loops
- What is the Difference between struct and class in terms of Access Modifier?
- By default all the struct members are private while by default class members are public.
- By default all the struct members are protected while by default class members are private.
- By default all the struct members are public while by default class members are private.
- By default all the struct members are public while by default class members are protected.
- Inline functions are invoked at the time of
- Run time
- Compile time
- Depends on how it is invoked
- Both b and c above
- What is shallow copy?
- A shallow copy creates a copy of the dynamically allocated objects too.
- A shallow copy just copies the values of the data as they are.
- A shallow copy creates a copy of the statically allocated objects too
- Both b and c above
- What is deep copy?
- A deep copy creates a copy of the dynamically allocated objects too.
- A deep copy just copies the values of the data as they are.
- A deep copy creates a copy of the statically allocated objects too
- Both b and c above
- Which of the following below is /are a valid iterator type?
- Input Iterator
- Backward Iterator
- Forward Iterator
- Both a and c above
- What defines a general set of operations that will be applied to various types of data?
- Template class
- Function template
- Class template
- Both a and c above
- Under which of the following circumstances, synchronization takes place?
- When the file is closed
- When the buffer is empty
- Explicitly, with manipulators
- both a and c
- Which of the following functions below can be used Allocate space for array in memory?
- calloc()
- malloc()
- Realloc()
- both a and b
- Statement scanf(“%d”,80);
- Assign an integer to variable i
- Give an error message
- Print the value of i
- Assign an float to variable i
- STL is based on which of the following programming paradigms?
- Structured Programming
- Object Oriented Programming (OOP)
- Functional Programming
- Aspect Oriented Programming (AOP)
- STL is based on which of the following programmingparadigms?
- Structured Programming
- Object Oriented Programming (OOP)
- Functional Programming
- Aspect Oriented Programming (AOP)
- If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?
- parentheses ( )
- braces { }
- brackets [ ].
- arrows < >
- Which of the following members do get inherited but become private members in child class
- Public
- Private
- Protected
- All the above
- Which looping process is best used when the number of iterations is known?
- for
- while
- do-while
- all looping processes require that the iterations be known
- In a C language ‘3’ represents
- A digit
- An integer
- A character
- A word
- Which of the following is the most common way of implementing C++?
- C++ programs are directly compiled into native code by a compiler
- C++ programs are first compiled to intermediate code by a compiler and then executed by a virtual machine
- C++ programs are interpreted by an interpreter
- A C++ editor directly compiles and executes the program
- Which header file should we include for using std::auto_ptr?
- <memory>
- <alloc>
- <autoptr>
- <smartptr>
- Which of the following operators can be implemented as a nonmember operator?
#NAME?
- () (function call operator)
- [. (array access operator)
- + (addition operator)
- What is the implicit pointer that is passed as the first argument for nonstatic member functions?
- ‘self’ pointer
- std::auto_ptr pointer
- ‘Myself’ pointer
- ‘this’ pointer
- Which of the following operators can be overloaded?
- . (dot or member access operator)
- & (address-of operator)
- sizeof operator
- ?: (conditional operator)
- Which of the following operator cannot be overloaded?
#NAME?
- == (equality operator)
- –> (row operator)
- :: (cope resolution operator)
- Which of the following operators below allow to define the member functions of a class outside the class?
- ::
- ?
- 😕
- %
- Which of the following is not a valid conditional inclusions in preprocessor directives
- #ifdef
- #ifundef
- #endif
- #elif
- Which of the following is not a standard exception built in C++.
- std::bad_creat
- std::bad_alloc
- std::bad_cast
- std::bad_typeid
- If a member needs to have unique value for all the objects of that same class, declare the member as
- Global variable outside class
- Local variable inside constructor
- Static variable inside class
- Dynamic variable inside class
- Under which of the following circumstances, synchronization takes place?
- When the file is closed
- When the buffer is empty
- Explicitly, with manipulators
- both a and c
- Which of the following functions below can be used Allocate space for array in memory?
- calloc()
- malloc()
- Realloc()
- both a and b
- Which of the following is not a valid conditional inclusions in preprocessor directives
- #ifdef
- #ifundef
- #endif
- #elif
- Value of a in a = (b = 5, b + 5); is
- Junk value
- Syntax error
- 5
- 10
- Minimum number of temporary variable needed to swap the contents of 2 variables is:
- 1
- 2
- 3
- 0
- There is nothing like a virtual constructor of a class.
- False
- True
- C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time. This process is called as
- Static binding
- Dynamic Binding
- The output of this program is
int
main () { cout << “Hello World!” return 0; }
- Hello World
- Syntax error
- 0
- Hello World!
- The return value of the following code is
Class1& test(Class1 obj)
{
Class1 *ptr = new Class1();
………
return ptr;
}
- object of Class1
- reference to ptr
- reference of Class1
- object pointed by ptr
- The output of
{
int a = 5;
int b = 10;
cout << (a>b?a:b);
}
- 5
- 10
- Syntax error
- None of above
- The output of this program is
int a = 10;
void main()
{
int a = 20;
cout << a << ::a;
}
- Syntax error
- 10 20
- 20 10
- 20 20
- Observe following program and answer
class Example{
public: int a,b,c;
Example(){a=b=c=1;}
//Constructor 1
Example(int a){a = a; b = c = 1;}
//Constructor 2
Example(int a,int b){a = a; b = b; c = 1;}
//Constructor 3
Example(int a,int b,int c){ a = a; b = b; c = c;}
//Constructor 4
}
In the above example of constructor overloading, the following statement will call which constructor
Example obj = new Example (1,2,3);
- Constructor 2
- Constructor 4
- Constrcutor 1
- Type mismatch error
Leave a Reply