Which of the following is the correct way to declare a pointer to a function that returns an int and takes two int parameters?
Aint *ptr(int, int);
Bint (*ptr)(int, int);
Cint *ptr[int, int];
Dint ptr*(int, int);
Correct Answer:
B. int (*ptr)(int, int);
Explanation:
The correct syntax for a function pointer is: int (*ptr)(int, int);. The parentheses around (*ptr) are necessary to indicate that ptr is a pointer to a function, not a function returning a pointer. Option A declares a function returning an int pointer.
What is the correct syntax to pass a 2D array to a function in C?
Afunc(int arr[][])
Bfunc(int arr[rows][cols])
Cfunc(int arr[][cols])
Dfunc(int **arr)
Correct Answer:
C. func(int arr[][cols])
Explanation:
When passing a 2D array to a function, the number of columns must be specified, but the number of rows is optional. Option C is the standard correct syntax.