Govt Exams
p points to arr[0]. *p = 5 modifies arr[0]. Printing arr[0] displays 5.
Both p and q point to same address of x, so p == q evaluates to true (1).
free(NULL) is safe in C and does nothing. This is by design to prevent errors when freeing pointers.
In 64-bit systems, pointers are 8 bytes (64 bits) regardless of the data type they point to.
Double pointer (int **ptr) is the correct syntax for pointer to pointer. Single & is used in C++ references, not C.
char str[] = "ABC";
char *p = str;
printf("%c", *(p+2));
p+2 points to str[2] which is 'C'. Note: str[3] is null terminator.
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);
swap() exchanges values through pointers. x becomes 10, y becomes 5 after function call.
void* is a generic pointer. It can be cast to any other pointer type. No arithmetic can be done directly.
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", *(p+1), arr[1]);
p+1 points to second element (20). arr[1] is also 20. Both print the same value.
int *ptr;
On a 64-bit system, all pointers are 8 bytes regardless of the data type they point to.