ProgrammingHard
A 2D array is passed to a function that needs the number of rows. Which argument can it NOT rely on?
- A. An explicit rows argument passed by the caller
- B. A sentinel value stored in the last row
- C. sizeof of the parameter, since the parameter is a pointer and sizeof gives the pointer size
- D. A global constant set by the caller
Correct answer: C. sizeof of the parameter, since the parameter is a pointer and sizeof gives the pointer size
An array parameter adjusts to a pointer, so sizeof gives the pointer's size and cannot give the row count. The caller must pass the count.
More C Programming questions
- int a[3][3] = {0}; int p = a[1]; p[2] = 7; printf("%d", a[1][2]); What is printed?
- The number of ways to choose a 2 x 2 submatrix in a 4 x 4 matrix (choosing consecutive rows and columns) is what?
- Which of these statements about in-place transposition is correct?
- A table of size 5 uses h(k) = k % 5 with linear probing. Keys 15, 5, 10 and 3 are inserted in that order. How many slots are examined when…
- A hash table of size 5 uses h(k) = k mod 5 with linear probing. The keys 5, 10, 15 and 3 are inserted in that order into an empty table…
- A chained table has 4 buckets with h(k) = k % 4. Keys 1 and 5 are inserted with head insertion. Which key is first in bucket 1?