Govt Exams
Array names are pointer constants that point to the first element and cannot be reassigned, while pointer variables can be modified to point to different addresses.
void* is a generic pointer that can hold addresses of any data type and requires explicit typecasting when used.
int x = 20;
int *p = &x;
printf("%d", *p);
The * operator dereferences the pointer p, accessing the value it points to, which is 20.
The & (address-of) operator returns the memory address of the variable.
In a 64-bit system, all pointers occupy 8 bytes regardless of the data type they point to.
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.
The %p format specifier prints the pointer value as a memory address in hexadecimal format, not the dereferenced value.
Since an array pointer is passed, the function can access and modify the original array elements in the caller's scope.