Entrance Exams
Govt. Exams
Pointer arithmetic scales by data type size. p + 2 moves 2 * sizeof(int) bytes forward, pointing to arr[2].
NULL is explicitly set to address 0, while wild pointers contain garbage values from uninitialized memory.
Void pointers cannot perform pointer arithmetic (++, --, +n) directly. They must be cast to a specific type first.
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).
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d", sizeof(p));
p is a pointer, so sizeof(p) returns pointer size (8 bytes on 64-bit, 4 on 32-bit), not array size.
int x = 5;
int *const p = &x;
x = 10;
printf("%d", *p);
const pointer p cannot be changed, but x can be modified. *p prints current value of x which is 10.
int *p, *q;
p = q; // What happens?
p = q copies the address stored in q to p. Now both point to same location.
int arr[2][3] = {{1,2,3}, {4,5,6}};
int *p = (int*)arr;
printf("%d", *(p+4));
Array flattened: 1,2,3,4,5,6. p+4 points to 5th element which is 5.
Pointer multiplication is not allowed. Valid operations are addition, subtraction, increment, decrement, and comparison.
int a = 10;
int *p = &a;
int *q = p;
q = NULL;
printf("%d", *p);
q = NULL only changes q, not p. p still points to a, so *p prints 10.