Govt Exams
int *p = (int*)malloc(5 * sizeof(int));
int *q = p;
p = NULL;
free(q);
q still holds the address even though p is NULL. free(q) properly deallocates memory.
malloc(0) behavior is implementation-defined but typically returns a valid pointer. Freeing it is safe.
arr points to arr[0], p points to arr[2]. arr - p = -2 (p is 2 positions ahead).
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.