0% found this document useful (0 votes)
8 views2 pages

CS304 Imp Shorts

The document outlines key concepts in C++ including rules for templates and friends, static members in class templates, cursors and iterators, exception handling mechanisms, and the Standard Template Library (STL). It explains the differences between function and class templates, the use of lambda expressions, and the advantages of smart pointers. Additionally, it details various types of containers and iterators in STL, as well as the purpose of keywords like typename and auto.

Uploaded by

manineedy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

CS304 Imp Shorts

The document outlines key concepts in C++ including rules for templates and friends, static members in class templates, cursors and iterators, exception handling mechanisms, and the Standard Template Library (STL). It explains the differences between function and class templates, the use of lambda expressions, and the advantages of smart pointers. Additionally, it details various types of containers and iterators in STL, as well as the purpose of keywords like typename and auto.

Uploaded by

manineedy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1: What are the rules for templates and friends in C++?

There are 4 main rules: 1) A friend function to a non-template class can be a function template,
2) A friend function to a class template can be a non-template function, 3) A friend function to a
class template can be a function template, and 4) A friend class to a class template can be a
class template.
Q2: How do static members work with class templates?
Each instantiation of a class template has its own copy of static members. The static members
must be defined outside the class template definition.
Q3: What are cursors in programming?
Cursors are programming abstractions that allow traversing a collection of data elements
sequentially without exposing the underlying data structure.
Q4: What are iterators in C++?
Iterators are objects that allow traversing elements in a container, providing a common interface
for accessing elements regardless of the container type.
Q5: What are the main components of the Standard Template Library (STL)?
The main components are containers, algorithms, and iterators.
Q6: What are the different categories of iterators in STL?
The main categories are input iterators, output iterators, forward iterators, bidirectional iterators,
and random-access iterators.
Q7: What is exception handling in C++?
Exception handling is a mechanism for handling runtime errors or exceptional situations in a
program using try, catch, and throw keywords.
Q8: What is stack unwinding in exception handling?
Stack unwinding is the process of destroying local objects and calling destructors for automatic
objects when an exception is thrown, as the call stack is "unwound" to find an appropriate
exception handler.
Q9: What is the purpose of the try block in exception handling?
To enclose the code that might throw an exception.
Q10: What is the purpose of the catch block in exception handling?
To handle exceptions that are thrown in the corresponding try block.
Q11: What is the purpose of the throw keyword in exception handling?
To explicitly throw an exception.
Q12: What are the advantages of using exception handling?
It separates error-handling code from normal code, allows errors to be propagated up the call
stack, and provides a mechanism for grouping and differentiating error types.
Q13: What is a template specialization?
A template specialization is a separate definition of a function or class template for a specific
data type.
Q14: What is partial template specialization?
Partial template specialization allows you to specialize a template for a subset of its template
parameters.
Q15: What is the difference between function templates and class templates?
Function templates generate function definitions, while class templates generate class
definitions. Class templates can have member functions and static members.
Q16: What is a non-type template parameter?
A non-type template parameter is a template parameter that is not a type, but a value of a
specific type, such as an integer or a pointer.
Q17: What is the purpose of the typename keyword in templates?
The typename keyword is used to specify that a dependent name in a template definition is a
type.
Q18: What is a function object (functor) in C++?
A function object is a class that overloads the function call operator (), allowing objects of the
class to be used as if they were functions.
Q19: What is the advantage of using function objects over regular functions?
Function objects can maintain state between calls and can be customized through their member
variables.
Q20: What is a lambda expression in C++?
A lambda expression is a convenient way to create anonymous function objects inline.
Q21: What is the syntax for a basic lambda expression?
capture clause -> return_type { function body }
Q22: What is the purpose of the capture clause in a lambda expression?
The capture clause specifies which variables from the enclosing scope should be available
inside the lambda function.
Q23: What is the Standard Template Library (STL)?
The STL is a collection of powerful, reusable, and adaptable software components in C++ that
provide common data structures and algorithms.
Q24: What are the main types of containers in STL?
Sequence containers (e.g., vector, list), associative containers (e.g., set, map), and container
adapters (e.g., stack, queue).
Q25: What is an algorithm in the context of STL?
An algorithm in STL is a function template that implements a procedure to be performed on
containers, such as sorting or searching.
Q26: What is the difference between vector and list in STL?
Vector provides random access and contiguous memory storage, while list provides bidirectional
sequential access and non-contiguous storage.
Q27: What is the purpose of the auto keyword in C++11?
The auto keyword allows the compiler to automatically deduce the type of a variable from its
initializer.
Q28: What is a smart pointer in C++?
A smart pointer is an object that acts like a pointer but provides additional features such as
automatic memory management.
Q29: What are the three main types of smart pointers in C++11?
unique_ptr, shared_ptr, and weak_ptr.
Q30: What is the purpose of unique_ptr?
To manage a single object and ensure it is deleted when the unique_ptr goes out of scope.

You might also like