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 211–220 of 490
Topics in C Programming
Q.211 Medium Pointers
What is the difference between NULL and a wild pointer?
A NULL points to 0, wild is uninitialized
B Both are same
C NULL is a constant, wild can vary
D NULL is type-safe, wild is not
Correct Answer:  A. NULL points to 0, wild is uninitialized
EXPLANATION

NULL is explicitly set to address 0, while wild pointers contain garbage values from uninitialized memory.

Test
Q.212 Medium Pointers
Which operation is NOT allowed on void pointers in C without explicit casting?
A Assignment
B Arithmetic operations
C Dereferencing
D Passing to functions
Correct Answer:  B. Arithmetic operations
EXPLANATION

Void pointers cannot perform pointer arithmetic (++, --, +n) directly. They must be cast to a specific type first.

Test
Q.213 Medium Pointers
Consider the code: int x = 10; int *p = &x; int **q = &p; What is the value of **q?
A 10
B Address of x
C Address of p
D Undefined
Correct Answer:  A. 10
EXPLANATION

q points to p, p points to x. **q dereferences twice: first gets p's value (address of x), second gets x's value (10).

Test
Q.214 Medium Pointers
What is the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d", sizeof(p));
A 12
B 8 or 4 depending on system
C 3
D Compilation error
Correct Answer:  B. 8 or 4 depending on system
EXPLANATION

p is a pointer, so sizeof(p) returns pointer size (8 bytes on 64-bit, 4 on 32-bit), not array size.

Test
Q.215 Medium Pointers
What is the output?
int x = 5;
int *const p = &x;
x = 10;
printf("%d", *p);
A 5
B 10
C Garbage value
D Compilation error
Correct Answer:  B. 10
EXPLANATION

const pointer p cannot be changed, but x can be modified. *p prints current value of x which is 10.

Test
Q.216 Medium Pointers
Which of the following is correct about pointer assignment?
int *p, *q;
p = q; // What happens?
A Copies the value p points to into q
B Makes p point to the same address as q
C Causes compilation error
D Allocates new memory for p
Correct Answer:  B. Makes p point to the same address as q
EXPLANATION

p = q copies the address stored in q to p. Now both point to same location.

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

Array flattened: 1,2,3,4,5,6. p+4 points to 5th element which is 5.

Test
Q.218 Medium Pointers
Which pointer operation is NOT valid in C?
A int *p, *q; p - q (pointer subtraction)
B int *p; p++ (pointer increment)
C int *p, *q; p * q (pointer multiplication)
D int *p; *p = 5 (pointer dereference assignment)
Correct Answer:  C. int *p, *q; p * q (pointer multiplication)
EXPLANATION

Pointer multiplication is not allowed. Valid operations are addition, subtraction, increment, decrement, and comparison.

Test
Q.219 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.

Test
Q.220 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.

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