โ Must-know
Further detail
C with Classes โ C++ โ multiparadigm system language
โ Must-know
A C++ development environment requires a text editor for writing code and a compiler for translating code into a language understood by the computer.
A basic Linux workflow creates a source file, compiles it with , and runs the executable with .
Further detail
Examples of integrated development environments include:
GCC is the GNU Compiler Collection, which provides compiler front-ends for C, C++, Objective-C, Fortran, Ada, and Go and includes runtime support libraries.
Write โ compile โ run
โ Must-know
Further detail
cout outputs, whereas cin inputs
๐ The extraction operator >> reads only one word from a string input because whitespace terminates the input.
๐ Reading a complete line after formatted input requires:
C++ identifier rules are:
cin stops at whitespace, whereas getline reads the line
โ Must-know
๐ Entities in a namespace can be accessed from outside it with the scope resolution operator ::, such as namesp1::value().
Further detail
The setw() manipulator, declared in <iomanip>, sets the field width for the next insertion operation.
Integer-base manipulators are:
Separate namespaces as labeled rooms containing same-named objects
โ Must-know
๐ C++ functions are either library functions supplied by the standard library or user-defined functions written by the programmer.
๐ A function prototype declares the return type, name, and parameter list followed by a semicolon, allowing the function to be implemented later.
Further detail
๐ A void function returns no value, although its parameter list may be written as empty parentheses or as void.
Declare โ define โ call โ return
โ Must-know
Character functions provided through <cctype> include:
Common string operations include:
Further detail
string objects provide richer operations, whereas character arrays use null termination
โ Must-know
๐ C++ permits overloaded functions with the same name when they differ in the number or types of parameters, but return type alone cannot distinguish overloads.
Further detail
A function call transfers execution to the function, whereas a declaration only describes it.
โ Must-know
A function template is instantiated by calling its name with template arguments in angle brackets followed by the function arguments.
The generic sum template returns the sum of two values using and can be instantiated as sum<int>(x,y) or sum<double>(n,m).
Further detail
๐ A template may use multiple type parameters, such as T and U, so its arguments can resolve to different types.
๐ An auto return type lets the compiler deduce a common return type and helps avoid narrowing when a template returns values of different types.
Picture one function-shaped mold producing versions for different types.
โ Must-know
Further detail
Base case โ induction hypothesis โ induction step.
โ Must-know
๐ Formula โ The factorial recursion is with the base case .
๐ Formula โ The Fibonacci recursion is with base cases f(0)=0 and f(1)=1.
๐ Formula โ The recursive power algorithm uses with the base case .
Further detail
๐ Formula โ The recursive sum of the digits of n is with sum(0)=0.
๐ Formula โ Multiplication by recursion is defined by with multiply(m,0)=0.
Factorial โ Fibonacci โ power โ digit operations.
โ Must-know
๐ Formula โ The recursive array sum is with sumOfArray(a,0)=0.
Further detail
A recursive palindrome check compares the first and last elements, returns false when they differ, and recursively checks the inner sequence when they match.
A recursive character printer stops at '\0' and otherwise prints the first character before recursing on the remaining array.
Shrink the input โ solve the smaller problem โ combine or return the result.
โ Must-know
๐ C++ class members can be private, protected, or public: private members are accessible within the class, protected members also within derived classes, and public members from anywhere the object is visible.
Further detail
๐ Members declared with the class keyword are private by default until another access specifier is encountered.
A class is the type or blueprint, whereas an object is its instantiated variable.
โ Must-know
๐ Constructors cannot be called explicitly like regular member functions and execute once when a new object of the class is created.
๐ A default constructor takes no parameters and is called when an object is declared without initialization arguments.
Further detail
๐ A constructor can be overloaded with different numbers or types of parameters, and the compiler selects the version matching the objectโs initialization arguments.
A constructor initializes an object automatically, whereas a regular member function must be called.
โ Must-know
๐ A constructor is executed automatically once when a new object is created, whereas it cannot be called explicitly like a regular member function.
๐ An empty pair of parentheses after a class name can declare a function instead of creating an object, so Rectangle rectc(); declares a function returning Rectangle rather than calling the default constructor.
Further detail
Parentheses can declare a function, whereas braces explicitly construct an object.
โ Must-know
A constructor can initialize data members in a member initialization list placed after a colon and before the constructor body, such as : width(x), height(y).
If a member object is omitted from the member initialization list, it is default-constructed before the constructor body executes.
The arrow operator -> accesses a member through a pointer to an object, while the dot operator . accesses a member directly through an object.
Further detail
๐ Member initialization lists are required when a member class cannot be default-constructed and are useful when default construction would be wasteful before reinitialization.
๐ An array of dynamically allocated class objects is accessed with indexing such as baz[0] and baz[1] and must be released with delete[].
The dot accesses an object directly, whereas the arrow accesses an object through a pointer.
โ Must-know
๐ Public inheritance is declared with the syntax class ChildClass : public ParentClass { /* additional fields and methods */ };.
Further detail
Inheritance from a base class โ derived classes reuse and extend its fields and methods.
โ Must-know
๐ A C++ program can use multiple source files either by including a header file or by compiling and linking separate source files with g++ commands.
๐ Separating a class interface in a .h file from its implementation in a .cpp file is good practice, whereas mixing method prototypes and implementations in one header file is identified as bad practice.
Further detail
๐ A header file can contain a namespace with function definitions, and another source file can access those functions with an #include directive and the namespace.
๐ The preprocessor guard pattern #ifndef Rectangle_H, #define Rectangle_H, declarations, and #endif prevents a header file from being included multiple times.
Declare โ implement โ compile objects โ link the final executable.
| Feature | Operator or function | Role |
|---|---|---|
| cout | << | Outputs values or text |
| cin | >> | Reads whitespace-delimited input |
| getline | getline(cin, variable) | Reads a complete line |
| endl | << endl | Inserts a newline |
| Specifier | Accessible from class | Accessible from derived class | Accessible elsewhere |
|---|---|---|---|
| private | Yes | No | No |
| protected | Yes | Yes | No |
| public | Yes | Yes | Yes |
Test your knowledge on C++ Functions Recursion and OOP with 57 multiple-choice questions with detailed corrections.
1. Which description best defines a data structure?
2. A programmer writes ordered instructions that calculate a solution to a problem; what has the programmer created?
Memorize the key concepts of C++ Functions Recursion and OOP with 85 interactive flashcards.
What is a data structure in computing?
A logical or mathematical model for collecting and organizing data.
What defines an algorithm in computer science?
A set of instructions or rules for solving a problem or task.
What programming paradigms does C++ combine?
Object-oriented programming with procedural C.
Import your course and AI generates sheets, quizzes and flashcards in 30 seconds.
Sheet generator