What is the difference between pointer and array name in C?
Answer: B
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.
Q.522Medium
What will be the output?
int a[] = {10, 20, 30};
int *p = a;
printf("%d", *(p+2));
Answer: C
p points to a[0], p+2 points to a[2] which contains 30. Dereferencing gives 30.
Q.523Medium
What does calloc() do that malloc() doesn't?
Answer: B
calloc() takes two parameters (number of elements, size) and initializes all bytes to zero, while malloc() leaves memory uninitialized.
Q.524Medium
What is the output of this code?
int *p, *q;
int x = 5;
p = &x;
q = p;
printf("%d %d", *p, *q);
Answer: A
Both p and q point to the same variable x. Dereferencing both gives the value 5.
Q.525Medium
Which statement correctly declares a pointer to a pointer?
Answer: B
int **p declares a pointer to a pointer (double pointer). Each * adds one level of indirection.
Advertisement
Q.526Medium
What will be printed?
int x = 100, y = 200;
int *p = &x;
int *q = &y;
p = q;
printf("%d", *p);
Answer: B
p is reassigned to point to y (p = q). Dereferencing p now gives the value of y, which is 200.
Q.527Medium
What is the primary disadvantage of using free() without proper checks?
Answer: B
Calling free() on already freed memory or using a pointer after freeing it causes double-free errors and use-after-free bugs, leading to undefined behavior.
Q.528Medium
What will be the output?
char *str = "Hello";
printf("%c", *(str+1));
Answer: B
str points to 'H', str+1 points to 'e'. Dereferencing gives 'e'.
Q.529Hard
What is the relationship between arrays and pointers in C?
Answer: C
In most contexts, array names automatically decay to pointers to their first element. This is why array[i] is equivalent to *(array+i).
Q.530Hard
What will be the output?
int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
int *p = (int *)arr;
printf("%d", *(p+5));
Answer: B
Converting 2D array to int pointer treats it as 1D. p+5 points to the 6th element (0-indexed), which is 6.
Q.531Hard
What does realloc() do?
Answer: B
realloc() changes the size of previously allocated memory. It may return the same address or a new one depending on availability.
Q.532Medium
What is the output?
void func(int *arr) { arr[0] = 100; }
int main() {
int a[5] = {1,2,3,4,5};
func(a);
printf("%d", a[0]);
}
Answer: B
Arrays are passed by reference (as pointers). Changes made in func() affect the original array. a[0] becomes 100.
Q.533Medium
Which of the following is valid pointer arithmetic in C?
Answer: A
Valid pointer arithmetic includes addition/subtraction with integers and subtraction between pointers. Multiplication, division, and pointer addition are invalid.
Q.534Hard
What is the primary use of const pointer (int * const p)?
Answer: B
int * const p is a constant pointer - the pointer address cannot be changed, but the value it points to can be modified.
Q.535Easy
What is the output of the following code?
int x = 5;
int *p = &x;
int q = &p;
printf("%d", q);
Answer: A
q is a pointer to pointer p. **q dereferences p twice, giving the value of x which is 5.
Q.536Medium
Which of the following correctly declares a pointer to a function that takes two integers and returns an integer?
Answer: A
int (*ptr)(int, int) declares a pointer to a function. int *ptr(int, int) declares a function returning pointer to int.
Q.537Easy
What will be the size of the pointer variable on a 64-bit system?
int *ptr;
Answer: B
On a 64-bit system, all pointers are 8 bytes regardless of the data type they point to.
Q.538Easy
What is the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", *(p+1), arr[1]);
Answer: A
p+1 points to second element (20). arr[1] is also 20. Both print the same value.
Q.539Medium
What happens when you try to modify a string literal through a pointer?
char *str = "Hello";
str[0] = 'J';
Answer: B
String literals are stored in read-only memory. Attempting to modify causes undefined behavior or segmentation fault.
Q.540Medium
Consider the code:
int *p = NULL;
int *q = malloc(sizeof(int));
free(q);
free(q);
What is the issue here?
Answer: A
Freeing the same pointer twice causes double free error and undefined behavior. Should set q=NULL after first free.