ProgrammingHardGATE CS · Campus placements
void f(int a[10]) { printf("%zu", sizeof a); } Which statement about the result is correct?
- A. It prints 40 on every platform, because the bound 10 is part of the parameter
- B. It prints sizeof(int), because a is a single int
- C. It prints sizeof(int *), not 40, because the parameter is adjusted to a pointer
- D. It prints the size of the caller's array, because the array is passed by value
Correct answer: C. It prints sizeof(int *), not 40, because the parameter is adjusted to a pointer
An array parameter declaration adjusts to a pointer type, so sizeof a gives the size of a pointer. The 10 in the declarator is ignored, and the array is not copied.
More C Programming questions
- int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = m; printf("%d", ((p + 1) + 2)); prints what?
- Which statement about sizeof is correct when x is an int variable initialised to 5?
- char s[] = "hello"; printf("%zu %zu", sizeof s, strlen(s)); prints what?
- char names[] = {"ab", "cde", "f"}; What is strlen(names[0]) strlen(names[1]) + strlen(names[2])?
- int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int (ops[])(int, int) = {add, sub, add}; int r = 10; for…
- uint32t a = 4000000000u; uint32t s = a + a; What is s?