Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 121–130 of 291
Topics in C Programming
Q.121 Easy Pointers
How does free() handle a NULL pointer?
A Causes segmentation fault
B Does nothing (safe operation)
C Returns error code
D Undefined behavior
Correct Answer:  B. Does nothing (safe operation)
EXPLANATION

free(NULL) is safe in C and does nothing. This is by design to prevent errors when freeing pointers.

Test
Q.122 Easy Pointers
What is the size of a pointer in a 64-bit system?
A 2 bytes
B 4 bytes
C 8 bytes
D 16 bytes
Correct Answer:  C. 8 bytes
EXPLANATION

In 64-bit systems, pointers are 8 bytes (64 bits) regardless of the data type they point to.

Test
Q.123 Easy Pointers
What is the output?
char str[] = "ABC";
char *p = str;
printf("%c", *(p+2));
A A
B B
C C
D Null character
Correct Answer:  C. C
EXPLANATION

p+2 points to str[2] which is 'C'. Note: str[3] is null terminator.

Test
Q.124 Easy Pointers
What is the output?
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int x = 5, y = 10;
swap(&x, &y);
printf("%d %d", x, y);
A 5 10
B 10 5
C 10 10
D 5 5
Correct Answer:  B. 10 5
EXPLANATION

swap() exchanges values through pointers. x becomes 10, y becomes 5 after function call.

Test
Q.125 Easy Pointers
What does void *ptr represent?
A Generic pointer that can point to any data type
B Pointer that points to nothing
C Null pointer
D Invalid pointer declaration
Correct Answer:  A. Generic pointer that can point to any data type
EXPLANATION

void* is a generic pointer. It can be cast to any other pointer type. No arithmetic can be done directly.

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

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

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

Test
Q.129 Easy Pointers
Which of the following is a void pointer?
A A pointer that points to nothing
B A generic pointer that can point to any data type
C A pointer declared as void variable
D A pointer that has been deleted
Correct Answer:  B. A generic pointer that can point to any data type
EXPLANATION

void* is a generic pointer that can hold addresses of any data type and requires explicit typecasting when used.

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

The * operator dereferences the pointer p, accessing the value it points to, which is 20.

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