Assuming standard headers and using namespace std, what does this C++ code print? constexpr int cube(int n) { return n * n * n; } int main() { int arr; cout << sizeof(arr) / sizeof(arr); }
Correct answer B. 8
Explanation
A constexpr function can be evaluated at compile time when its arguments are constant expressions. cube(2) is therefore the constant 8 and is a valid array bound, giving an array of 8 ints. sizeof(arr) / sizeof(arr[0]) divides the total byte size by the element size to count elements, which yields 8.
Answer checked How we write and check questions
Discussion