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 41–50 of 100
Topics in C Programming
Q.41 Medium Pointers
What is the output?
int a = 10;
int *p = &a;
int *q = p;
q = NULL;
printf("%d", *p);
A 10
B NULL
C Segmentation fault
D Garbage value
Correct Answer:  A. 10
EXPLANATION

q = NULL only changes q, not p. p still points to a, so *p prints 10.

Take Test
Q.42 Medium Pointers
Consider the code:
int *p = NULL;
int *q = malloc(sizeof(int));
free(q);
free(q);
What is the issue here?
A Double free error
B Memory leak
C No issue, free() checks for NULL
D Compilation error
Correct Answer:  A. Double free error
EXPLANATION

Freeing the same pointer twice causes double free error and undefined behavior. Should set q=NULL after first free.

Take Test
Q.43 Medium Pointers
What happens when you try to modify a string literal through a pointer?
char *str = "Hello";
str[0] = 'J';
A String changes to Jello
B Undefined behavior/Runtime error
C Compilation error
D No change, str remains Hello
Correct Answer:  B. Undefined behavior/Runtime error
EXPLANATION

String literals are stored in read-only memory. Attempting to modify causes undefined behavior or segmentation fault.

Take Test
Q.44 Easy Pointers
What is the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", *(p+1), arr[1]);
A 20 20
B 10 20
C 20 10
D 30 30
Correct Answer:  A. 20 20
EXPLANATION

p+1 points to second element (20). arr[1] is also 20. Both print the same value.

Take Test
Q.45 Easy Pointers
What will be the size of the pointer variable on a 64-bit system?
int *ptr;
A 4 bytes
B 8 bytes
C Depends on int size
D 16 bytes
Correct Answer:  B. 8 bytes
EXPLANATION

On a 64-bit system, all pointers are 8 bytes regardless of the data type they point to.

Take Test
Q.46 Medium Pointers
Which of the following correctly declares a pointer to a function that takes two integers and returns an integer?
A int (*ptr)(int, int);
B int *ptr(int, int);
C int (*ptr[2])(int, int);
D int *ptr[2];
Correct Answer:  A. int (*ptr)(int, int);
EXPLANATION

int (*ptr)(int, int) declares a pointer to a function. int *ptr(int, int) declares a function returning pointer to int.

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

q is a pointer to pointer p. **q dereferences p twice, giving the value of x which is 5.

Take Test
Q.48 Hard Pointers
What is the primary use of const pointer (int * const p)?
A Prevent modification of the value pointed to
B Prevent modification of the pointer itself
C Prevent allocation of memory
D Prevent deallocation of memory
Correct Answer:  B. Prevent modification of the pointer itself
EXPLANATION

int * const p is a constant pointer - the pointer address cannot be changed, but the value it points to can be modified.

Take Test
Q.49 Medium Pointers
Which of the following is valid pointer arithmetic in C?
A p + 5 (where p is a pointer)
B p * 2 (where p is a pointer)
C p / 2 (where p is a pointer)
D p1 + p2 (where p1 and p2 are pointers)
Correct Answer:  A. p + 5 (where p is a pointer)
EXPLANATION

Valid pointer arithmetic includes addition/subtraction with integers and subtraction between pointers. Multiplication, division, and pointer addition are invalid.

Take Test
Q.50 Medium Pointers
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]);
}
A 1
B 100
C Garbage value
D Compilation error
Correct Answer:  B. 100
EXPLANATION

Arrays are passed by reference (as pointers). Changes made in func() affect the original array. a[0] becomes 100.

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