Govt Exams
The pre-increment operator ++x increments x first (from 5 to 6), then assigns the new value to y. So x = 6 and y = 6.
*p dereferences to a (10) and *q dereferences to b (20). Adding them: 10 + 20 = 30. Pointer arithmetic is used correctly here.
arr[5] accesses the element at index 5, which is at memory address (arr + 5). Array name arr acts as a pointer to the first element.
malloc() returns a void pointer (void*), which can be cast to any data type pointer as needed by the programmer.
const int *ptr makes the data constant (const int * ptr). int * const ptr makes the pointer constant. The position of const matters.
The ternary operator syntax is: condition ? value_if_true : value_if_false. Option B is the only correctly formatted statement.
++x increments x to 6 (pre-increment), then x++ returns 6 and increments x to 7. So: 6 + 6 = 12. Post-increment returns the old value.
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.
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.
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.