Govt. Exams
Entrance Exams
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.
int x = 5;
int *p = &x;
int **q = &p;
printf("%d", **q);
q is a pointer to pointer p. **q dereferences p twice, giving the value of x which is 5.
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.
ptr points to the first character of the string, so *ptr dereferences to 'H'. The %c format specifier prints a single character.
The & (address-of) operator returns the memory address of a variable.
The dereference operator (*) accesses the value at the address pointed to by p, which is the value 10.