Which of the following is a correct way to initialize a pointer to NULL?
Aint *ptr = 0;
Bint *ptr = NULL;
Cint *ptr = (void*)0;
DAll of the above
Correct Answer:
D. All of the above
Explanation:
All three methods are correct ways to initialize a pointer to NULL. 0, NULL, and (void*)0 all represent a null pointer. NULL is typically a macro defined as 0 or ((void*)0) in the standard library.
What is the output of the expression: 10 / 3 * 3 in C?
A10
B9
C3.33
DCannot be determined
Correct Answer:
B. 9
Explanation:
Division and multiplication have the same precedence and are evaluated left-to-right. Step 1: 10 / 3 = 3 (integer division). Step 2: 3 * 3 = 9. Therefore, the result is 9.
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.