Govt. Exams
Entrance Exams
int * const p is a constant pointer - the pointer address cannot be changed, but the value it points to can be modified.
realloc() changes the size of previously allocated memory. It may return the same address or a new one depending on availability.
int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
int *p = (int *)arr;
printf("%d", *(p+5));
Converting 2D array to int pointer treats it as 1D. p+5 points to the 6th element (0-indexed), which is 6.
In most contexts, array names automatically decay to pointers to their first element. This is why array[i] is equivalent to *(array+i).
Uninitialized pointers contain garbage values. Dereferencing them accesses arbitrary memory locations, causing runtime errors or undefined behavior.
malloc() allocated memory must be freed using free(p), not free(&p). After freeing, it's good practice to set p = NULL.
Returning a pointer to a local variable is unsafe because the variable ceases to exist after the function returns, creating a dangling pointer.
int x = 50;
int *p = &x;
int *q = p;
q = NULL;
printf("%d", *p);
Setting q to NULL doesn't affect p. p still points to x, so *p is 50.
void pointers are generic pointers that must be cast to appropriate type before dereferencing.
int *p = (int*)malloc(sizeof(int));
*p = 5;
free(p);
p = NULL;
This is proper memory management: allocate, use, free, and nullify to prevent dangling pointer.