Which operator is used to get the address of a variable in C?
The & operator (address-of operator) returns the memory address of a variable.
What will be the size of a pointer variable on a 64-bit system?
On a 64-bit system, a pointer is 8 bytes (64 bits) regardless of the data type it points to.
What is a NULL pointer?
A NULL pointer is a pointer that points to memory address 0, indicating it doesn't point to any valid memory location.
What is the output?
int a = 5;
int *p = &a;
int q = &p;
printf("%d", q);
q is a pointer to pointer p. **q dereferences q to get p, then dereferences p to get the value 5.
What happens when you increment a pointer?
int arr[5] = {1,2,3,4,5};
int *p = arr;
p++;
When a pointer is incremented, it moves to the next element based on the data type size (pointer arithmetic).
Advertisement
Which of the following is NOT a valid pointer declaration?
& is a reference operator used in C++, not in C. In C, pointers are declared using *.
What is the output?
int x = 10, y = 20;
int *p = &x;
int *q = &y;
p = q;
printf("%d", *p);
After p = q, pointer p now points to y. So *p gives the value of y, which is 20.
Identify the output:
char *str = "Hello";
printf("%c", *str);
*str dereferences the pointer to get the first character of the string, which is 'H'.
What is the difference between *p++ and (*p)++?
Due to operator precedence, *p++ is equivalent to *(p++), incrementing the pointer. (*p)++ explicitly increments the value.
What will be printed?
int arr[] = {1, 2, 3};
int *p = arr;
printf("%d", *(p+2));
p+2 points to the third element of the array. *(p+2) dereferences it to get 3.
What is a wild pointer?
A wild pointer is an uninitialized pointer that contains an arbitrary/garbage memory address.
What is the output?
int *p = NULL;
if(p) printf("Not NULL");
else printf("NULL");
NULL pointer evaluates to false in a conditional, so the else block executes.
Which of the following correctly allocates memory for 10 integers?
malloc requires the size in bytes. For 10 integers, we need 10 * sizeof(int) bytes.
What is a dangling pointer?
A dangling pointer is a pointer that points to memory that has been freed or deallocated.
What does the following code do?
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.
What will be the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", arr[1], *(p+1));
arr[1] and *(p+1) both access the second element of the array, which is 20.
Which statement is true about void pointers?
void pointers are generic pointers that must be cast to appropriate type before dereferencing.
What is the output?
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.
A pointer variable stores the _____ of another variable.
Pointers store memory addresses of variables. The address-of operator (&) retrieves this address.
What is the size of a pointer variable on a 32-bit system?
On a 32-bit system, all pointers are 4 bytes (32 bits) regardless of the data type they point to.