ProgrammingHardGATE CS · Product company OA

Given int m[3][4];, why can m not be passed to a function declared void f(int **p);?

  1. A. m is too large to pass by value
  2. B. A two-dimensional array cannot be passed to any function
  3. C. int ** can only point to dynamically allocated memory
  4. D. m converts to int (*)[4], a pointer to a row of 4 ints, which is a different type with a different layout from a pointer to pointers

Correct answer: D. m converts to int (*)[4], a pointer to a row of 4 ints, which is a different type with a different layout from a pointer to pointers

m is one contiguous block of 12 ints, so it decays to a pointer to its first row. f would read the ints as if they were row pointers. Declare f(int (*p)[4]) or f(int p[][4]) instead.

More C Programming questions

Exams that ask this topic