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.
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.
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.
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).
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].
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.
What happens when you initialize a structure variable without assigning values?
A Members are automatically set to 0 B Members contain garbage values C Compilation error occurs D Members are set to NULL
Uninitialized local structure variables contain garbage values. Global structures are automatically initialized to zero.
Which of the following correctly declares a pointer to a structure?
A struct emp *ptr; B *struct emp ptr; C struct *emp ptr; D emp struct *ptr;
Correct syntax is 'struct typename *pointerName;'. Option A follows proper declaration syntax.
What is the difference between struct and typedef struct?
A No difference, both are identical B typedef struct allows direct variable declaration without 'struct' keyword C struct is faster than typedef struct D typedef struct is used only in C++
typedef struct creates an alias, so you can declare variables directly using the alias name without repeating 'struct'.
What will be printed? struct s { int a; char b; int c; }; printf("%lu", sizeof(struct s));
A 9 bytes B 12 bytes C 13 bytes D 8 bytes
Due to memory alignment/padding: int a(4) + char b(1) + 3 padding bytes + int c(4) = 12 bytes.
How do you access a member of a structure using a pointer?
A ptr.member B ptr->member C *ptr.member D ptr*member
The arrow operator (->) is used to access structure members through a pointer. Dot (.) is for direct variables.
What is the purpose of padding in structures?
A To waste memory intentionally B To align data for faster CPU access C To prevent hacking D To increase security
Padding ensures that structure members are aligned in memory according to their natural boundaries, improving CPU access speed.
Consider: union u { int x; double y; }; What is sizeof(u)?
A 4 bytes B 8 bytes C 12 bytes D 16 bytes
The size of a union is equal to its largest member. double is typically 8 bytes, which is larger than int (4 bytes).
Consider struct test { int x; double y; char z; }; What is the minimum size of this structure (assuming 4-byte int, 8-byte double)?
A 13 bytes B 16 bytes C 20 bytes D 24 bytes
Due to padding: int (4) + padding (4) + double (8) + char (1) + padding (3) = 24 bytes. The structure aligns to the largest member size.
What will be printed by this code? struct s { int a; struct s *next; }; struct s *ptr; sizeof(struct s)
A 4 bytes B 8 bytes C 12 bytes D 16 bytes
sizeof(int) = 4 bytes, sizeof(pointer) = 8 bytes (on 64-bit systems). Total = 12 bytes. Pointers are fixed size regardless of what they point to.