CPP
Free Section Starter Challenge
25 min
3. Functions & Pass-by-Reference (&)
Overview: Avoid costly memory copies by passing arguments with `const Type&`.
Concept & Syntax Guide
Passing large objects by value makes full copies in memory. Using `const std::string& str` passes a direct reference without copying, maximizing execution speed.
Hands-On Practice Exercise
Write a Zero-Copy String Formatter
Write a function `void printTemplate(const std::string& name)` that prints "Template: " followed by the name.
Target Output:
Template: NovaPulse AI
Need a hint? Click here to reveal
Hint: Check syntax carefully and make sure your code contains:
Template: NovaPulse AI
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10