Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
consteval int kb(int n) { return n * 1024; }
int main() {
int n;
std::cin >> n;
std::cout << kb(n) << '\n';
return 0;
}
- A kb must return long
- B A consteval function must be evaluated at compile time, but n is read at run time; use constexpr instead (which may run at run time) Correct
- C cin cannot read ints
- D 1024 is too big
Correct Answer: Option B
kb(4) would be fine – its argument is a constant.
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!