Which pointer operation is NOT valid in C?
A int *p, *q; p - q (pointer subtraction) B int *p; p++ (pointer increment) C int *p, *q; p * q (pointer multiplication) D int *p; *p = 5 (pointer dereference assignment)
Pointer multiplication is not allowed. Valid operations are addition, subtraction, increment, decrement, and comparison.
What is the output? int arr[2][3] = {{1,2,3}, {4,5,6}}; int *p = (int*)arr; printf("%d", *(p+4));
A 5 B 4 C 6 D 1
Array flattened: 1,2,3,4,5,6. p+4 points to 5th element which is 5.
What does void *ptr represent?
A Generic pointer that can point to any data type B Pointer that points to nothing C Null pointer D Invalid pointer declaration
void* is a generic pointer. It can be cast to any other pointer type. No arithmetic can be done directly.
What is the output? void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } int x = 5, y = 10; swap(&x, &y); printf("%d %d", x, y);
A 5 10 B 10 5 C 10 10 D 5 5
swap() exchanges values through pointers. x becomes 10, y becomes 5 after function call.
Consider: int arr[] = {1,2,3,4,5}; int *p = arr + 2; What is arr - p?
A -2 B 2 C Address difference D Compilation error
arr points to arr[0], p points to arr[2]. arr - p = -2 (p is 2 positions ahead).
What is malloc(0) likely to return?
A NULL pointer B Valid pointer to 0 bytes C Garbage value D Compilation error
malloc(0) behavior is implementation-defined but typically returns a valid pointer. Freeing it is safe.
What is the output? char str[] = "ABC"; char *p = str; printf("%c", *(p+2));
A A B B C C D Null character
p+2 points to str[2] which is 'C'. Note: str[3] is null terminator.
Which of the following is correct about pointer assignment? int *p, *q; p = q; // What happens?
A Copies the value p points to into q B Makes p point to the same address as q C Causes compilation error D Allocates new memory for p
p = q copies the address stored in q to p. Now both point to same location.
What is the output? int x = 5; int *const p = &x; x = 10; printf("%d", *p);
A 5 B 10 C Garbage value D Compilation error
const pointer p cannot be changed, but x can be modified. *p prints current value of x which is 10.
What will be printed? int *p = (int*)malloc(5 * sizeof(int)); int *q = p; p = NULL; free(q);
A Compilation error B Memory leak C Program runs successfully D Double free error
q still holds the address even though p is NULL. free(q) properly deallocates memory.
What is the difference between arr and &arr if arr is an array? int arr[5];
A Both are identical B arr is pointer to first element, &arr is pointer to whole array C &arr is pointer to first element, arr is pointer to whole array D They have different sizes
arr decays to pointer to first element (int*). &arr is pointer to whole array (int(*)[5]). Pointer arithmetic differs.
What is the output? int arr[] = {10, 20, 30}; int *p = arr; printf("%d", sizeof(p));
A 12 B 8 or 4 depending on system C 3 D Compilation error
p is a pointer, so sizeof(p) returns pointer size (8 bytes on 64-bit, 4 on 32-bit), not array size.
What is the size of a pointer in a 64-bit system?
A 2 bytes B 4 bytes C 8 bytes D 16 bytes
In 64-bit systems, pointers are 8 bytes (64 bits) regardless of the data type they point to.
Consider the code: int x = 10; int *p = &x; int q = &p; What is the value of q?
A 10 B Address of x C Address of p D Undefined
q points to p, p points to x. **q dereferences twice: first gets p's value (address of x), second gets x's value (10).
Which operation is NOT allowed on void pointers in C without explicit casting?
A Assignment B Arithmetic operations C Dereferencing D Passing to functions
Void pointers cannot perform pointer arithmetic (++, --, +n) directly. They must be cast to a specific type first.
What is the difference between NULL and a wild pointer?
A NULL points to 0, wild is uninitialized B Both are same C NULL is a constant, wild can vary D NULL is type-safe, wild is not
NULL is explicitly set to address 0, while wild pointers contain garbage values from uninitialized memory.
In the expression: int arr[5]; int *p = arr; What does p + 2 represent?
A Address of arr[0] + 2 bytes B Address of arr[2] C Value 2 D Address of arr[0] + 8 bytes
Pointer arithmetic scales by data type size. p + 2 moves 2 * sizeof(int) bytes forward, pointing to arr[2].
What is the purpose of the const keyword in: int * const p;?
A Pointer points to constant data B Pointer itself is constant C Both pointer and data are constant D Data becomes read-only
const after * means the pointer address cannot change, but the data it points to can be modified.
How does free() handle a NULL pointer?
A Causes segmentation fault B Does nothing (safe operation) C Returns error code D Undefined behavior
free(NULL) is safe in C and does nothing. This is by design to prevent errors when freeing pointers.
Which scenario demonstrates a dangling pointer?
A Pointer declared but not initialized B Pointer freed but still used afterward C Pointer set to NULL D Pointer pointing to static variable
Dangling pointer occurs when memory is freed but pointer still references that location. This causes undefined behavior.