What is the output?
int a = 5;
int *p = &a;
int q = &p;
printf("%d", q);
Answer: A
q is a pointer to pointer p. **q dereferences q to get p, then dereferences p to get the value 5.
Q.2Medium
What happens when you increment a pointer?
int arr[5] = {1,2,3,4,5};
int *p = arr;
p++;
Answer: B
When a pointer is incremented, it moves to the next element based on the data type size (pointer arithmetic).
Q.3Medium
What is the output?
int x = 10, y = 20;
int *p = &x;
int *q = &y;
p = q;
printf("%d", *p);
Answer: B
After p = q, pointer p now points to y. So *p gives the value of y, which is 20.
Q.4Medium
What will be printed?
int arr[] = {1, 2, 3};
int *p = arr;
printf("%d", *(p+2));
Answer: C
p+2 points to the third element of the array. *(p+2) dereferences it to get 3.
Q.5Medium
What is a wild pointer?
Answer: B
A wild pointer is an uninitialized pointer that contains an arbitrary/garbage memory address.
Advertisement
Q.6Medium
What is the output?
int *p = NULL;
if(p) printf("Not NULL");
else printf("NULL");
Answer: B
NULL pointer evaluates to false in a conditional, so the else block executes.
Q.7Medium
Which of the following correctly allocates memory for 10 integers?
Answer: B
malloc requires the size in bytes. For 10 integers, we need 10 * sizeof(int) bytes.
Q.8Medium
What is a dangling pointer?
Answer: A
A dangling pointer is a pointer that points to memory that has been freed or deallocated.
Q.9Medium
What will be the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", arr[1], *(p+1));
Answer: A
arr[1] and *(p+1) both access the second element of the array, which is 20.
Q.10Medium
A void pointer can be used to store addresses of variables of any data type. However, it must be cast before dereferencing. Which statement about void pointers is FALSE?
Answer: B
A void pointer cannot be directly dereferenced. It must be cast to the appropriate pointer type first.
Q.11Medium
Consider the code: int arr[] = {5, 10, 15, 20}; int *ptr = arr; ptr++; What does ptr now point to?
Answer: C
Pointer arithmetic increments by the size of the data type. For int (4 bytes), ptr++ moves to the next integer, which is arr[1].
Q.12Medium
Which of the following best describes a dangling pointer situation?
Answer: B
A dangling pointer occurs when it points to memory that no longer exists, typically after free() or when a local variable goes out of scope.
Q.13Medium
Consider: int x = 5; int *p = &x; int q = &p; What is the value of q?
Answer: A
q is a pointer to pointer p. **q dereferences twice: first to get p, then to get the value x, which is 5.
Q.14Medium
Which memory allocation function does NOT initialize allocated memory to zero?
Answer: D
malloc() and realloc() return uninitialized memory with garbage values. calloc() initializes all bytes to zero.
Q.15Medium
Consider: int arr[5] = {1, 2, 3, 4, 5}; int *p = arr; What is the value of *(p+2)?
Answer: B
p points to arr[0]. p+2 points to arr[2], and *(p+2) dereferences to the value at arr[2], which is 3.
Q.16Medium
A function needs to modify a variable in the calling function. Which parameter passing method is appropriate?
Answer: B
To modify a variable in the calling function, you must pass its address (pointer). Pass by value creates a copy and cannot modify the original.
Q.17Medium
Consider: void func(int *arr, int size); This function prototype suggests that func will:
Answer: B
Since an array pointer is passed, the function can access and modify the original array elements in the caller's scope.
Q.18Medium
What will be the output of: int x = 10; int *p = &x; printf("%p", p); (assuming typical system output)
Answer: B
The %p format specifier prints the pointer value as a memory address in hexadecimal format, not the dereferenced value.
Q.19Medium
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.20Medium
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.