ProgrammingHardProduct-company placement · C++

What is printed?

What is printed?
void f(int a[10]) { cout << (sizeof(a) == sizeof(int*)); }
int main() {
    int arr[10];
    cout << sizeof(arr) / sizeof(arr[0]);
    f(arr);
}
  1. A. 1010
  2. B. 100
  3. C. 101
  4. D. 11

Correct answer: C. 101

In main, sizeof(arr) is the size of the whole array (10 elements). A parameter declared as int a[10] is adjusted to int*, so inside f sizeof(a) is just the size of a pointer.

More OOP with C++ and Java questions

Exams that ask this topic