Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 201–210 of 490
Topics in C Programming
Q.201 Medium Pointers
In pointer to function declaration: int (*ptr)(int, int); which statement is correct?
A ptr is a function returning pointer to int
B ptr is a pointer to a function taking two ints and returning int
C ptr is an array of function pointers
D ptr cannot be used to call functions
Correct Answer:  B. ptr is a pointer to a function taking two ints and returning int
EXPLANATION

The parentheses around *ptr indicate ptr is a pointer. It points to a function that takes two int parameters and returns an int.

Test
Q.202 Medium Pointers
What will be the output?
int arr[5] = {1,2,3,4,5};
int *p = arr;
p += 2;
printf("%d", *p);
A 1
B 2
C 3
D Garbage value
Correct Answer:  C. 3
EXPLANATION

p points to arr[0]. After p += 2, p points to arr[2] which contains value 3. Pointer arithmetic moves by element size.

Test
Q.203 Medium Pointers
Which of the following is a valid pointer comparison in C?
A if(p1 > p2 && p1 < p3) where p1, p2, p3 are unrelated pointers
B if(ptr == NULL) to check if pointer is null
C if(p1 == 5) where p1 is a pointer
D if(p1 - p2 > 10) where p1 and p2 point to different arrays
Correct Answer:  B. if(ptr == NULL) to check if pointer is null
EXPLANATION

Comparing pointers with NULL is valid. Comparing unrelated pointers or subtracting pointers from different arrays is undefined behavior.

Test
Q.204 Medium Pointers
For dynamic 2D array allocation using int **arr = (int**)malloc(n*sizeof(int*)); what must be done next?
A Directly assign values to arr[i][j]
B Allocate memory for each row using a loop
C Call free() immediately
D Call realloc() for memory expansion
Correct Answer:  B. Allocate memory for each row using a loop
EXPLANATION

After allocating memory for pointers, each pointer (row) must be allocated memory individually in a loop before accessing arr[i][j].

Test
Q.205 Medium Pointers
In: int *p; *p = 10; What is the issue?
A Syntax error
B p is uninitialized (wild pointer)
C Memory leak
D Type mismatch
Correct Answer:  B. p is uninitialized (wild pointer)
EXPLANATION

p is not initialized to valid address. Dereferencing causes undefined behavior (writing to random memory location).

Test
Q.206 Medium Pointers
Which of the following is valid pointer comparison?
A p > 5
B p == q (different types)
C p < q (valid pointers)
D p + 10
Correct Answer:  C. p < q (valid pointers)
EXPLANATION

Pointers of same type can be compared using <, >, ==, !=. Comparing with integers or different types is invalid.

Test
Q.207 Medium Pointers
For function: void modify(int *x) { *x = 20; } If called as modify(&a), what changes?
A The pointer itself
B The value of variable a
C The function parameter
D Nothing
Correct Answer:  B. The value of variable a
EXPLANATION

Passing address allows function to modify original variable. *x = 20 changes the value at that address.

Test
Q.208 Medium Pointers
Which scenario demonstrates a dangling pointer?
A Pointer declared but not initialized
B Pointer freed but still used afterward
C Pointer set to NULL
D Pointer pointing to static variable
Correct Answer:  B. Pointer freed but still used afterward
EXPLANATION

Dangling pointer occurs when memory is freed but pointer still references that location. This causes undefined behavior.

Test
Q.209 Medium Pointers
What is the purpose of the const keyword in: int * const p;?
A Pointer points to constant data
B Pointer itself is constant
C Both pointer and data are constant
D Data becomes read-only
Correct Answer:  B. Pointer itself is constant
EXPLANATION

const after * means the pointer address cannot change, but the data it points to can be modified.

Test
Q.210 Medium Pointers
In the expression: int arr[5]; int *p = arr; What does p + 2 represent?
A Address of arr[0] + 2 bytes
B Address of arr[2]
C Value 2
D Address of arr[0] + 8 bytes
Correct Answer:  B. Address of arr[2]
EXPLANATION

Pointer arithmetic scales by data type size. p + 2 moves 2 * sizeof(int) bytes forward, pointing to arr[2].

Test
IGET
IGET AI
Online · Exam prep assistant
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