
Advanced C++ Concepts
Presentation
•
Computers
•
University
•
Practice Problem
•
Medium
Dr. Moriarty
Used 4+ times
FREE Resource
6 Slides • 14 Questions
1
In C++, pass by value means a function receives a copy of the argument, so changes made to the parameter do not affect the original variable.
Pass by reference allows the function to work directly with the original variable by using its memory address, so changes made inside the function are reflected in the original variable outside the function.
2
Multiple Choice
What will this code print?
After modifyValue: 20, After modifyReference: 30
After modifyValue: 10, After modifyReference: 30
After modifyValue: 20, After modifyReference: 10
After modifyValue: 10, After modifyReference: 10
3
Multiple Choice
What will this code print?
After doubleValue: 10, After doubleReference: 20
After doubleValue: 5, After doubleReference: 10
After doubleValue: 5, After doubleReference: 5
After doubleValue: 10, After doubleReference: 10
4
In C++, a static variable inside a function retains its value between function calls, unlike a regular local variable that is re-initialized each time the function is called. This allows the variable to maintain state across multiple invocations of the function, effectively acting like a persistent, function-level global variable. Static variables are initialized only once and keep their value throughout the program's lifetime.
5
Multiple Choice
What will this code print?
Counter: 1, Counter: 1, Counter: 1
Counter: 0, Counter: 1, Counter: 2
Counter: 1, Counter: 2, Counter: 3
Counter: 1, Counter: 2, Counter: 2
6
Multiple Choice
What will this code print?
Num: 5, Num: 5, Num: 5, Num: 5
Num: 5, Num: 10, Num: 15, Num: 20
Num: 10, Num: 15, Num: 20, Num: 25
Num: 10, Num: 20, Num: 30, Num: 40
7
Default Parameters
In C++, default parameters allow you to specify a default value for a function parameter so that if the argument is omitted during a function call, the default value is used. This makes functions more flexible by allowing them to be called with fewer arguments. Default parameters must be defined from right to left in the function signature to avoid ambiguity.
8
Multiple Choice
What will this code print?
Hello, Alice!
Hello, Alice!
Hello, Alice!
Hello, Guest!
Hello, Guest!
Hello, Guest!
The code will not compile due to missing parameters.
9
Multiple Choice
What will this code print?
a: 5, b: 10, c: 20
a: 7, b: 15, c: 20
a: 3, b: 8, c: 20
a: 5, b: 10, c: 20
a: 7, b: 15, c: 20
a: 3, b: 8, c: 12
a: 5, b: 10, c: 20
a: 7, b: 10, c: 20
a: 3, b: 8, c: 20
The code will not compile due to incorrect default parameter usage.
10
Template Functions
In C++, template functions allow you to write a single function that can work with different data types, making code more reusable and flexible.
By defining a function template with a type parameter (e.g., template<typename T>), the compiler can generate a version of the function for each specific type used during a function call. This feature is particularly useful for creating generic algorithms that work with any data type.
11
Multiple Choice
What will this code print?
5 5
3.14 3.14
Hello Hello
5 5
3.14 3.14
Compilation error due to using a string literal
5 5
3.14 3.14
HelloHello
The code will not compile due to incorrect template usage.
12
Multiple Choice
Which of the following statements about template functions in C++ is true?
Template functions must be defined for each specific data type before they are used.
Template functions can only accept one type parameter.
Template functions allow a single function definition to work with multiple data types.
Template functions cannot be used with built-in data types like int or double.
13
Multiple Choice
Extra Credit: Who is this Zelda character?
Tingle
Gannon
Beedle
Sephiroth
14
In C++, inline functions are functions that suggest to the compiler to replace the function call with the actual code of the function to reduce the overhead of function calls.
This can improve performance for small, frequently called functions, but the compiler may ignore the inline suggestion for complex functions.
Declaring a function as inline does not guarantee that it will be inlined, as this decision is ultimately up to the compiler.
15
Multiple Choice
What will this print?
Square of 4 is: 4
Square of 5 is: 5
Square of 4 is: 16
Square of 5 is: 25
Square of 4 is: 16
Square of 5 is: 20
The code will not compile due to inline function usage.
16
Multiple Choice
Which of the following statements about inline functions in C++ is true?
Inline functions are guaranteed to be inlined by the compiler.
Inline functions help reduce the overhead of function calls by suggesting the compiler to replace the function call with its body.
Inline functions can only be defined within the class declaration.
Inline functions cannot include loops or complex logic.
17
in C++ const correctness ensures that variables, function parameters, and return types that should not be modified are declared as const. This helps prevent unintended changes to data, making code safer and easier to maintain. Using const can also improve code readability by clearly indicating which values are intended to remain constant.
18
Multiple Choice
what will this code print?
5
6
nothing
compile error
19
Multiple Choice
Which of the following statements about const correctness in C++ is true?
A const parameter passed by reference allows the function to modify the original argument.
Declaring a function parameter as const ensures that the function cannot modify the parameter within its body.
Using const with a function return type guarantees that the function's return value cannot be modified by the caller.
A const variable can be modified after its initial declaration as long as it is within the same function.
20
Multiple Choice
Extra Credit: What Mega Man boss is this?
Drill Man
Metal Man
Crash Man
Waluigi
In C++, pass by value means a function receives a copy of the argument, so changes made to the parameter do not affect the original variable.
Pass by reference allows the function to work directly with the original variable by using its memory address, so changes made inside the function are reflected in the original variable outside the function.
Show answer
Auto Play
Slide 1 / 20
SLIDE
Similar Resources on Wayground
20 questions
Introducción a EXCEL
Presentation
•
University
12 questions
Personal Pronouns
Presentation
•
University
16 questions
Pengantar Arsitektur dan Organisasi Komputer
Presentation
•
University
13 questions
Lección Python 1
Presentation
•
University
13 questions
Good Shape
Presentation
•
12th Grade - University
16 questions
Digestive System
Presentation
•
University
11 questions
Robotics
Presentation
•
University
15 questions
Passive Voice
Presentation
•
University
Popular Resources on Wayground
10 questions
Safety Day 2026 – Student Review
Quiz
•
9th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade
Discover more resources for Computers
20 questions
Disney Trivia
Quiz
•
University
10 questions
Spanish Greetings and Goodbyes!
Presentation
•
6th Grade - University
20 questions
Physical or Chemical Change/Phases
Quiz
•
8th Grade - University
39 questions
Unit 7 Key Terms
Quiz
•
11th Grade - University
25 questions
SER and Subject Pronouns
Quiz
•
8th Grade - University
38 questions
Unit 6 Key Terms
Quiz
•
11th Grade - University
19 questions
Key Concepts in Buddhism
Quiz
•
University
0 questions
Cell Domain Basic Review (Biology)
Quiz
•
University