Practice mode C++

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.