Question 1
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
void f(int a[10]) { std::cout << sizeof(a) << ' '; }
int main() {
int a[10];
std::cout << sizeof(a) << ' ';
f(a);
std::cout << sizeof(a) / sizeof(a[0]) << '\n';
return 0;
}
- A 40 8 10 Correct
- B 40 40 10
- C 10 10 10
- D 40 4 10
Correct Answer: Option A
In main, a is a real array of 10 ints (40 bytes). The parameter int a[10] is adjusted to int*, so sizeof gives the pointer size, 8. The 10 in the parameter is ignored.
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!