Question 10
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
int main() {
int helper(int x) {
return x + 1;
}
std::cout << helper(5) << '\n';
return 0;
}
- A helper must be declared static
- B C++ does not allow function definitions inside other functions; define helper outside main or use a lambda Correct
- C x must be a reference
- D helper must return void
Correct Answer: Option B
A local lambda gives the same effect: auto helper = [](int x) { return x + 1; };.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!