Skip to main content

Important Introduction to Programming Short Questions

Chapter: 42
Question 1:
How is a template class instantiated?
Answer: By specifying the data type in angle brackets, e.g., Stack<int>, which creates a stack for integers.
Chapter: 42
Question 2:
What are non-type parameters in templates?
Answer: Non-type parameters are constants used in template definitions, such as array sizes.
Chapter: 42
Question 3:
How does a static member behave in a template class?
Answer: A static member is unique to each type instantiated from the template but shared among objects of the same type.
Chapter: 42
Question 4:
Can templates work with user-defined data types?
Answer: Yes, templates can be instantiated with user-defined classes as long as they support necessary functions and interfaces.
Chapter: 42
Question 5:
What is a friend function in the context of templates?
Answer: A friend function is granted access to the private members of a class and can be defined for template classes.
Chapter: 42
Question 6:
How does a friend function handle different template instantiations?
Answer: It can be specified to be a friend for particular template instantiations or all instantiations based on the template's data type.
Chapter: 42
Question 7:
What is the Standard Template Library (STL)?
Answer: STL is a library of pre-written, tested template classes and functions for common data structures and algorithms.
Chapter: 42
Question 8:
What is the primary advantage of using STL?
Answer: STL provides a tested code base for commonly used data structures and algorithms, reducing development time and errors.
Chapter: 42
Question 9:
How does template code help with compiler optimizations?
Answer: Templates allow for type-specific optimizations because the type is known at compile time.
Chapter: 42
Question 10:
What is a potential disadvantage of templates?
Answer: Templates can lead to complex compiler errors and make code harder to read if misused.