Unit 6 - Practice Quiz

CSE202 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 What is the primary purpose of exception handling in C++?

A. To improve compilation speed
B. To allow syntax errors to pass
C. To handle run-time errors and abnormal conditions
D. To optimize memory usage

2 Which keyword is used to raise an exception?

A. raises
B. try
C. catch
D. throw

3 What happens during 'stack unwinding' in exception handling?

A. The program restarts from main()
B. Destructors of automatic objects are called as control leaves scopes
C. The stack memory is increased
D. Global variables are reset

4 Which block contains the code that might generate an exception?

A. try
B. template
C. catch
D. throw

5 How do you define a catch block that handles all types of exceptions?

A. catch(void)
B. catch(all)
C. catch(Exception e)
D. catch(...)

6 When using multiple catch blocks, how should they be ordered?

A. Random order
B. Specific to general
C. Alphabetical order
D. General to specific

7 What is the syntax to rethrow an exception currently being handled?

A. throw;
B. throw e;
C. return;
D. rethrow;

8 If an exception is thrown but not caught anywhere in the program, which function is called by default?

A. stop()
B. terminate()
C. abort()
D. exit()

9 Can a destructor throw an exception safely?

A. No, syntax error
B. No, it generally terminates the program if thrown during stack unwinding
C. Yes, always
D. Yes, but only integer exceptions

10 Which header file is required for standard exception classes like std::exception?

A. <trycatch>
B. <exception>
C. <stdexcept>
D. <error>

11 What is a C++ Template?

A. A blueprint for creating a family of classes or functions
B. A mechanism to hide data
C. A type of inheritance
D. A library of graphics

12 Which keyword is used to declare a template?

A. type
B. template
C. typename
D. generic

13 In the syntax template <typename T>, what does T represent?

A. A placeholder for a data type
B. The return type
C. A specific integer value
D. The class name

14 Can keywords class and typename be used interchangeably in a template parameter list?

A. Yes, they are equivalent in this context
B. No, typename is deprecated
C. Yes, but class is preferred for functions
D. No, class is for classes and typename is for primitives

15 What is function template overloading?

A. Hiding a template function
B. Defining multiple templates with the same name but different parameters
C. Cannot overload templates
D. Calling a template function recursively

16 When a class template inherits from a non-template class, it is called:

A. Standard inheritance behavior
B. Mixed inheritance
C. Template inheritance
D. Invalid inheritance

17 Which of the following is a valid Non-Type Template Parameter?

A. float value
B. string literal
C. dynamic object
D. int value

18 What is 'Template Specialization'?

A. Defining a specific implementation for a particular data type
B. Deleting a template
C. Creating a template inside another template
D. Using a template for integers only

19 What happens at compile time when a template is instantiated?

A. The compiler generates the code for the specific type
B. The compiler creates a void pointer implementation
C. Nothing, it happens at runtime
D. The compiler ignores the template

20 Can a template class have static data members?

A. No
B. Yes, but they cannot be initialized
C. Yes, shared by all instances of all types
D. Yes, each instantiation has its own copy of the static member

21 What does STL stand for?

A. System Template Library
B. Structured Template Language
C. Standard Type List
D. Standard Template Library

22 What are the three main components of STL?

A. Containers, Algorithms, Iterators
B. Classes, Objects, Methods
C. Files, Streams, Buffers
D. Inputs, Processes, Outputs

23 Which component acts as a bridge between containers and algorithms?

A. Allocator
B. Functor
C. Adapter
D. Iterator

24 Which of the following is a Sequence Container?

A. stack
B. map
C. vector
D. set

25 Which header file is needed to use generic algorithms like sort()?

A. <stl>
B. <vector>
C. <algorithm>
D. <algo>

26 What is the underlying data structure of a std::vector?

A. Hash Table
B. Doubly Linked List
C. Linked List
D. Dynamic Array

27 What is the underlying data structure of a std::list?

A. Doubly Linked List
B. Binary Tree
C. Dynamic Array
D. Stack

28 Which iterator type does std::vector support?

A. Input Iterator only
B. Random Access Iterator
C. Bidirectional Iterator
D. Forward Iterator

29 What is the time complexity for random access in a std::list?

A. O(n*n)
B. O(n)
C. O(1)
D. O(log n)

30 Which function adds an element to the end of a vector?

A. insert()
B. push_back()
C. enqueue()
D. add()

31 Which function removes the last element of a vector?

A. extract()
B. remove_last()
C. delete()
D. pop_back()

32 Which of the following operations is faster in std::list compared to std::vector?

A. Sorting
B. Memory usage
C. Random access
D. Insertion in the middle

33 What does the begin() function return?

A. An iterator to the first element
B. The first value
C. An iterator to the last element
D. A pointer to the memory

34 What does the end() function return?

A. The last element
B. NULL
C. An iterator to the position just past the last element
D. An iterator to the last element

35 How do you access the element at index 3 in a vector v safely with bounds checking?

A. v.get(3)
B. v[3]
C. *(v+3)
D. v.at(3)

36 What happens to the capacity of a vector when it gets full?

A. It automatically increases, typically doubling its size
B. It throws an exception
C. It deletes old elements
D. It stops accepting elements

37 Which header file is required to use std::vector?

A. <vec>
B. <array>
C. <vector>
D. <list>

38 Can std::vector store elements of different data types?

A. Yes, it is loosely typed
B. Yes, using void pointers
C. Only if defined as vector<var>
D. No, it is a homogeneous container

39 Which operator is used to dereference an iterator to get the value it points to?

A. *
B. ::
C. ->
D. &

40 In std::list, what type of iterator is provided?

A. Forward only
B. Bidirectional
C. None
D. Random Access

41 What is the result of v.size() on an empty vector v?

A. Exception
B. 1
C. 0
D. Garbage value

42 What is the difference between size() and capacity() in a vector?

A. Size is in bytes, capacity is in elements
B. They are the same
C. Size is used memory, capacity is allocated memory
D. Capacity is used memory, size is allocated memory

43 How do you check if a container v is empty?

A. v.size() == null
B. v.checkEmpty()
C. v.null()
D. v.empty()

44 Which function clears all elements from a vector?

A. clear()
B. erase()
C. delete()
D. remove()

45 In a template, what is 'Class Template Inheritance'?

A. Copying code manually
B. Creating a class inside a function
C. Inheritance is not allowed in templates
D. Deriving a class template from a template or non-template base class

46 What keyword allows an iterator to move to the next element?

A. next()
B. move()
C. >> (Shift operator)
D. ++ (Increment operator)

47 Does std::list support the [] operator?

A. Only if the list is sorted
B. Yes
C. No
D. Only for read access

48 In exception handling, which logic applies to derived/base class catches?

A. Base class catch must appear before Derived class catch
B. They cannot exist in the same try-catch block
C. Order does not matter
D. Derived class catch must appear before Base class catch

49 Which method inserts elements into a vector at a specific position?

A. push()
B. put()
C. insert()
D. add()

50 What is the return type of the bad_alloc exception?

A. It is a type thrown, usually when new fails
B. Memory failure
C. NULL
D. void