Home Subjects C Programming Pointers

C Programming
Pointers

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 51–60 of 100
Topics in C Programming
Q.51 Hard Pointers
What does realloc() do?
A Allocates new memory block
B Resizes an existing allocated memory block and returns new address
C Frees memory and allocates new
D Initializes memory to zero
Correct Answer:  B. Resizes an existing allocated memory block and returns new address
EXPLANATION

realloc() changes the size of previously allocated memory. It may return the same address or a new one depending on availability.

Take Test
Q.52 Hard Pointers
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));
A 5
B 6
C 8
D Garbage value
Correct Answer:  B. 6
EXPLANATION

Converting 2D array to int pointer treats it as 1D. p+5 points to the 6th element (0-indexed), which is 6.

Take Test
Q.53 Hard Pointers
What is the relationship between arrays and pointers in C?
A Arrays are pointers
B Pointers are arrays
C Array names decay to pointers to their first element in most contexts
D No relationship
Correct Answer:  C. Array names decay to pointers to their first element in most contexts
EXPLANATION

In most contexts, array names automatically decay to pointers to their first element. This is why array[i] is equivalent to *(array+i).

Take Test
Q.54 Medium Pointers
What will be the output?
char *str = "Hello";
printf("%c", *(str+1));
A H
B e
C l
D Compilation error
Correct Answer:  B. e
EXPLANATION

str points to 'H', str+1 points to 'e'. Dereferencing gives 'e'.

Take Test
Q.55 Medium Pointers
What is the primary disadvantage of using free() without proper checks?
A Memory leak
B Double free error or use-after-free vulnerability
C Slower program execution
D Compilation warning
Correct Answer:  B. Double free error or use-after-free vulnerability
EXPLANATION

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.

Take Test
Q.56 Medium Pointers
What will be printed?
int x = 100, y = 200;
int *p = &x;
int *q = &y;
p = q;
printf("%d", *p);
A 100
B 200
C Address of y
D Garbage value
Correct Answer:  B. 200
EXPLANATION

p is reassigned to point to y (p = q). Dereferencing p now gives the value of y, which is 200.

Take Test
Q.57 Medium Pointers
Which statement correctly declares a pointer to a pointer?
A int *p;
B int **p;
C int *&p;
D int &*p;
Correct Answer:  B. int **p;
EXPLANATION

int **p declares a pointer to a pointer (double pointer). Each * adds one level of indirection.

Take Test
Q.58 Medium Pointers
What is the output of this code?
int *p, *q;
int x = 5;
p = &x;
q = p;
printf("%d %d", *p, *q);
A 5 5
B Address Address
C 5 Garbage
D Compilation error
Correct Answer:  A. 5 5
EXPLANATION

Both p and q point to the same variable x. Dereferencing both gives the value 5.

Take Test
Q.59 Medium Pointers
What does calloc() do that malloc() doesn't?
A Allocates more memory
B Initializes allocated memory to zero
C Allocates memory faster
D Returns a void pointer
Correct Answer:  B. Initializes allocated memory to zero
EXPLANATION

calloc() takes two parameters (number of elements, size) and initializes all bytes to zero, while malloc() leaves memory uninitialized.

Take Test
Q.60 Medium Pointers
What will be the output?
int a[] = {10, 20, 30};
int *p = a;
printf("%d", *(p+2));
A 10
B 20
C 30
D Garbage value
Correct Answer:  C. 30
EXPLANATION

p points to a[0], p+2 points to a[2] which contains 30. Dereferencing gives 30.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips