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 handle run-time errors and abnormal conditions
B. To allow syntax errors to pass
C. To improve compilation speed
D. To optimize memory usage

2 Which keyword is used to raise an exception?

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

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

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

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

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

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

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

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

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

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

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

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

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

9 Can a destructor throw an exception safely?

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

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

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

11 What is a C++ Template?

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

12 Which keyword is used to declare a template?

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

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

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

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

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

15 What is function template overloading?

A. Cannot overload templates
B. Hiding a template function
C. Defining multiple templates with the same name but different parameters
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. Template inheritance
C. Mixed inheritance
D. Invalid inheritance

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

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

18 What is 'Template Specialization'?

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

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

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

20 Can a template class have static data members?

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

21 What does STL stand for?

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

22 What are the three main components of STL?

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

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

A. Adapter
B. Functor
C. Allocator
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. <algorithm>
B. <vector>
C. <stl>
D. <algo>

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

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

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

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

28 Which iterator type does std::vector support?

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

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

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

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

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

31 Which function removes the last element of a vector?

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

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

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

33 What does the begin() function return?

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

34 What does the end() function return?

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

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 stops accepting elements
C. It deletes old elements
D. It throws an exception

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

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

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

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

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. Random Access
B. None
C. Bidirectional
D. Forward only

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

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

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

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

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

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

44 Which function clears all elements from a vector?

A. delete()
B. clear()
C. erase()
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. >> (Shift operator)
B. ++ (Increment operator)
C. move()
D. next()

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

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

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

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

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

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

50 What is the return type of the bad_alloc exception?

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