1. What is STL in C++?

STL (Standard Template Library) is a powerful library in C++ that provides
ready-made classes and functions for data structures and algorithms.
It helps in writing efficient and reusable code.

2. What are the three main components of STL?

The three main components are:
1. Containers
2. Algorithms
3. Iterators

3. What is a Container in STL?

Containers are data structures used to store data.
Examples: vector, list, map, set, queue, stack.

4. What are types of Containers?

1. Sequence Containers
2. Associative Containers
3. Unordered Containers
4. Container Adapters

5. What is a Sequence Container?

Sequence containers store elements in sequential order.
Examples: vector, list, deque, array.

6. What is vector?

vector is a dynamic array that automatically resizes itself.
It provides fast random access.

7. What is list?

list is a doubly linked list that allows fast insertion and deletion.

8. What is deque?

deque (double-ended queue) allows insertion and deletion from both ends.

9. What is array in STL?

array is a fixed-size container introduced in C++11.

10. What is an Associative Container?

Associative containers store elements in sorted order.
Examples: set, multiset, map, multimap.

11. What is set?

set stores unique elements in sorted order.

12. What is multiset?

multiset allows duplicate elements.

13. What is map?

map stores key-value pairs in sorted order by key.

14. What is multimap?

multimap allows duplicate keys.

15. What is unordered_set?

unordered_set stores unique elements in no particular order using hashing.

16. What is unordered_map?

unordered_map stores key-value pairs using hash table.

17. What is Container Adapter?

Container adapters modify interface of existing containers.
Examples: stack, queue, priority_queue.

18. What is stack?

stack follows LIFO (Last In First Out) principle.

19. What is queue?

queue follows FIFO (First In First Out) principle.

20. What is priority_queue?

priority_queue stores elements in priority order (largest by default).

21. What is an Iterator?

Iterator is an object that points to elements inside containers.
It works like a pointer.

22. Types of Iterators?

Input, Output, Forward, Bidirectional, Random Access.

23. What is begin() and end()?

begin() returns iterator to first element.
end() returns iterator to element after last element.

24. What are Algorithms in STL?

Algorithms are predefined functions like sort, find, count, reverse.

25. What is sort()?

sort() arranges elements in ascending order by default.

26. What is find()?

find() searches for element in container.

27. What is count()?

count() counts occurrences of a value.

28. What is reverse()?

reverse() reverses the order of elements.

29. What is accumulate()?

accumulate() calculates sum of elements.

30. What is binary_search()?

binary_search() checks if element exists in sorted container.

31. What is lower_bound()?

Returns iterator to first element not less than given value.

32. What is upper_bound()?

Returns iterator to first element greater than given value.

33. What is equal_range()?

Returns range of elements equal to given value.

34. What is emplace()?

Constructs element directly inside container without copy.

35. Difference between push_back() and emplace_back()?

push_back() copies/moves object.
emplace_back() constructs object in place.

36. What is capacity()?

Returns total allocated memory size of container.

37. What is size()?

Returns number of elements stored.

38. What is reserve()?

reserve() increases capacity of vector.

39. What is shrink_to_fit()?

Reduces capacity to fit current size.

40. What is erase()?

erase() removes elements from container.

41. What is clear()?

clear() removes all elements.

42. What is splice() in list?

Transfers elements from one list to another.

43. What is merge()?

merge() combines two sorted containers.

44. What is unique()?

Removes consecutive duplicate elements.

45. What is remove()?

remove() shifts elements but does not change container size.

46. What is transform()?

Applies function to range of elements.

47. What is lambda expression?

Lambda is an anonymous function used in algorithms.

48. What is function object (functor)?

An object that behaves like a function using operator().

49. What is complexity of vector access?

Random access in vector is O(1).

50. Why is STL important in interviews?

STL improves coding speed, efficiency, and demonstrates strong
understanding of data structures and algorithms.

5. What is a Template in C++?

A template is a feature in C++ that allows writing generic and reusable code.
It enables functions and classes to operate with different data types
without rewriting code.

52. What are the types of Templates?

There are two main types:
1. Function Templates
2. Class Templates

53. What is a Function Template?

A function template allows a single function to work with different data types
using a placeholder type.

54. What is a Class Template?

A class template allows creating a class that works with multiple data types.

55. What is Template Syntax?

Template syntax begins with:
template <typename T>
Here T is a generic data type.

56. What is typename keyword?

typename specifies that a template parameter is a type.
It is interchangeable with class keyword in templates.

57. What is Template Instantiation?

Template instantiation occurs when the compiler generates code
for a specific data type used with the template.

58. What is Explicit Template Instantiation?

It forces compiler to generate template code for a specific type manually.

59. What is Template Specialization?

Template specialization allows defining custom behavior for a specific data type.

60. What is Full Template Specialization?

Full specialization defines a completely separate implementation
for a particular data type.

61. What is Partial Template Specialization?

Partial specialization customizes behavior for some template parameters
but not all.

62. What is Non-Type Template Parameter?

A template parameter that is not a type but a constant value
such as integer or pointer.

63. What is Variadic Template?

Variadic templates allow passing variable number of arguments
using parameter packs.

64. What is Template Metaprogramming?

Template metaprogramming is a technique where templates
are used to perform computations at compile time.

65. What is SFINAE?

Substitution Failure Is Not An Error (SFINAE) is a rule
that allows template substitution failure without compilation error.

66. What is enable_if?

enable_if is a template utility used to enable or disable
functions based on conditions.

67. What is constexpr in templates?

constexpr allows compile-time constant expressions.
It works well with template metaprogramming.

68. What is Template Deduction?

Template deduction allows compiler to automatically determine
template argument types from function arguments.

69. What is Perfect Forwarding?

Perfect forwarding preserves value category (lvalue/rvalue)
while passing arguments to another function.

70. What is std::forward?

std::forward is used with universal references to implement
perfect forwarding.

71. What is std::move?

std::move converts lvalue into rvalue reference
to enable move semantics.

72. What is CRTP?

Curiously Recurring Template Pattern is a technique
where a class inherits from a template class instantiated with itself.

73. What are Template Aliases?

Template aliases use ‘using’ keyword to simplify complex template types.

74. What is Template Recursion?

Template recursion is recursive instantiation of templates
used in compile-time calculations.

75. What is std::tuple?

std::tuple is a class template that can hold multiple values
of different data types.

76. What is std::pair?

std::pair stores two values, possibly of different types.

77. What is Type Traits?

Type traits provide compile-time information about data types.
Example: std::is_integral.

78. What is static_assert?

static_assert checks conditions at compile time.

79. What is Concept in C++20?

Concepts define constraints on template parameters
to improve error messages and code clarity.

80. What is requires clause?

requires clause specifies template constraints using concepts.

81. What is Fold Expression?

Fold expressions simplify operations over parameter packs
in variadic templates.

82. What is std::variant?

std::variant is a type-safe union introduced in C++17.

83. What is std::any?

std::any stores any type of value.

84. What is std::optional?

std::optional represents optional value (may or may not contain value).

85. What is Tag Dispatching?

Tag dispatching selects function implementation
based on type traits.

86. What is Expression Templates?

Expression templates optimize operations by avoiding
temporary objects.

87. What is Template Bloat?

Template bloat occurs when many template instantiations
increase binary size.

88. What is inline namespace in templates?

Inline namespace allows versioning of templates.

89. What is Template Argument Deduction Guide?

Introduced in C++17 to guide compiler for class template deduction.

90. What is Dependent Name?

A name dependent on template parameter that requires
typename or template keyword.

91. What is Compile-time Polymorphism using Templates?

Templates provide compile-time polymorphism without
runtime overhead.

92. Difference between Macros and Templates?

Templates are type-safe and checked by compiler.
Macros are simple text replacement.

93. What is Template Parameter Pack?

Parameter pack allows multiple template parameters.

94. What is auto with Templates?

auto allows automatic type deduction with templates.

95. What is Deduction Failure?

Deduction failure occurs when compiler cannot determine
template parameter type.

96. What is Constraint Template?

Constraint templates restrict allowed template types
using concepts.

97. What is Template Instantiation Depth?

Maximum recursive depth allowed during template instantiation.

98. What are Advantages of Templates?

Code reuse, type safety, performance, compile-time computation.

99. What are Disadvantages of Templates?

Complex error messages, code bloat, longer compilation time.

100. Why are Templates Important in Interviews?

Templates demonstrate understanding of generic programming,
compile-time optimization, and modern C++ concepts.

📢 Join Our WhatsApp Channel

💼 Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.

👉 Join WhatsApp Now

📢 Join Our Telegram Channel

💼 Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!

👉 Join Telegram

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 - 2025 itfreesource.com

Enable Notifications OK No thanks