Govt. Exams
Entrance Exams
int *p;
*p = 10;
p is declared but not initialized to point to any valid memory location. Dereferencing an uninitialized pointer causes undefined behavior.
Which statement is TRUE?
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.
int x = 10;
int *p = &x;
int **q = &p;
printf("%d", **q);
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.
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.
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.