For function: void modify(int *x) { *x = 20; } If called as modify(&a), what changes?
A The pointer itself B The value of variable a C The function parameter D Nothing
Passing address allows function to modify original variable. *x = 20 changes the value at that address.
What is the result of: int x = 5; int *p = &x; int *q = p; if p == q?
A 0 (false) B 1 (true) C Undefined D Compiler error
Both p and q point to same address of x, so p == q evaluates to true (1).
In pointer to function: int (*ptr)(int, int); What does this declare?
A Function returning pointer to int B Pointer to function returning int with 2 int parameters C Array of pointers D Pointer to array of ints
Parentheses around *ptr give pointer priority. It's a pointer to a function taking 2 ints and returning int.
What happens with: int arr[10]; int *p = arr; *p = 5; printf("%d", arr[0]);?
A Prints garbage B Prints 5 C Compiler error D Prints 10
p points to arr[0]. *p = 5 modifies arr[0]. Printing arr[0] displays 5.
Which of the following is valid pointer comparison?
A p > 5 B p == q (different types) C p < q (valid pointers) D p + 10
Pointers of same type can be compared using <, >, ==, !=. Comparing with integers or different types is invalid.
In: int *p; *p = 10; What is the issue?
A Syntax error B p is uninitialized (wild pointer) C Memory leak D Type mismatch
p is not initialized to valid address. Dereferencing causes undefined behavior (writing to random memory location).
What is the output of: printf("%p", NULL);?
A 0x0 B NULL C Implementation-defined (typically 0x0 or empty) D Compilation error
%p prints pointer values. NULL representation depends on implementation, commonly shown as 0x0 or (nil).
For dynamic 2D array: int arr = (int )malloc(n * sizeof(int*)); What's missing?
A Nothing, code is complete B Allocating memory for each row C Casting malloc result D Type checking
This allocates row pointers only. Each row needs allocation: arr[i] = (int*)malloc(m * sizeof(int));
What is the relationship between arrays and pointers?
A Arrays are pointers B Pointers are arrays C Array name decays to pointer in most contexts D They are unrelated
Array name acts as pointer to first element in expressions but they're distinct. &arr and arr differ in type.
Consider: const int *p; and int * const q; Which statement is true?
A Both prevent modification of data B First prevents pointer change, second prevents data change C First prevents data change, second prevents pointer change D Both are identical
const int *p: pointer can change, data cannot. int * const q: pointer cannot change, data can be modified.
What is the output of the following code? int x = 10; int *p = &x; int **q = &p; printf("%d", **q);
A 10 B Address of x C Address of p D Garbage value
q is a pointer to pointer p. **q dereferences q twice: first to get p, then to get the value of x which is 10.
Consider the declaration: const int *p; and int * const q; Which statement is TRUE?
A Both p and q cannot be modified B p points to a constant integer; q is a constant pointer to integer C Both declarations are identical D Both p and q can be modified freely
const int *p means p can change but the data it points to cannot. int * const q means q cannot change but the data it points to can be modified.
For dynamic 2D array allocation using int arr = (int )malloc(n*sizeof(int*)); what must be done next?
A Directly assign values to arr[i][j] B Allocate memory for each row using a loop C Call free() immediately D Call realloc() for memory expansion
After allocating memory for pointers, each pointer (row) must be allocated memory individually in a loop before accessing arr[i][j].
What is the primary issue with this code? int *p; *p = 10;
A Syntax error B Pointer p is uninitialized and points to garbage memory C The value 10 cannot be assigned through a pointer D Missing return statement
p is declared but not initialized to point to any valid memory location. Dereferencing an uninitialized pointer causes undefined behavior.
Which of the following is a valid pointer comparison in C?
A if(p1 > p2 && p1 < p3) where p1, p2, p3 are unrelated pointers B if(ptr == NULL) to check if pointer is null C if(p1 == 5) where p1 is a pointer D if(p1 - p2 > 10) where p1 and p2 point to different arrays
Comparing pointers with NULL is valid. Comparing unrelated pointers or subtracting pointers from different arrays is undefined behavior.
What will be the output? int arr[5] = {1,2,3,4,5}; int *p = arr; p += 2; printf("%d", *p);
A 1 B 2 C 3 D Garbage value
p points to arr[0]. After p += 2, p points to arr[2] which contains value 3. Pointer arithmetic moves by element size.
In pointer to function declaration: int (*ptr)(int, int); which statement is correct?
A ptr is a function returning pointer to int B ptr is a pointer to a function taking two ints and returning int C ptr is an array of function pointers D ptr cannot be used to call functions
The parentheses around *ptr indicate ptr is a pointer. It points to a function that takes two int parameters and returns an int.
Consider a function void modify(int *x) { *x = 20; } called as modify(&y). What happens?
A y is passed by value; changes don't affect original y B Address of y is passed; changes inside modify affect original y C y is copied to a temporary variable D The function cannot access y
When &y is passed to a function expecting a pointer parameter, the address is passed. Changes via pointer dereference affect the original variable.