C++ syntax beyond C, namespaces, references, const correctness, std::string, std::vector basics, streams and function overloading.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a namespace in C++?
Show answer
A scope region that holds a set of identifiers to avoid naming conflicts between different parts of code or libraries
- How do you declare a namespace?
Show answer
namespace NamespaceName { /* declarations */ }
- How do you access a member of a namespace?
Show answer
Use the scope resolution operator: NamespaceName::memberName
- What does 'using namespace std;' do?
Show answer
Brings all names from the std namespace into the current scope, so you can use them without the std:: prefix
- What is a reference in C++?
Show answer
An alias to an existing variable that acts like another name for that variable
- What is the syntax for declaring a reference?
Show answer
Type& referenceName = existingVariable;
- Can a reference be null in C++?
Show answer
No, a reference must always refer to a valid object and cannot be null
- Can a reference be reassigned to refer to a different variable?
Show answer
No, once a reference is bound to a variable, it always refers to that same variable
- What is the main difference between a reference and a pointer?
Show answer
References cannot be null, cannot be reassigned, and do not require dereferencing; pointers can be all three
- What is a const reference?
Show answer
A reference to a constant that prevents modification of the referenced object through that reference
- What is const correctness in C++?
Show answer
Using the const keyword appropriately to prevent unintended modifications and make intent explicit
- Are 'int const x' and 'const int x' equivalent?
Show answer
Yes, both declare a constant integer; const can appear before or after the type
- What does 'const' on a function parameter do?
Show answer
Prevents the function from modifying the parameter
- What is std::string?
Show answer
A standard library class that represents a dynamic sequence of characters
- Which header must you include to use std::string?
Show answer
#include <string>