Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 121–130 of 303
Topics in C Programming
Q.121 Easy Pointers
What happens with: int arr[10]; int *p = arr; *p = 5; printf("%d", arr[0]);?
A Prints garbage
B Prints 5
C Compiler error
D Prints 10
Correct Answer:  B. Prints 5
EXPLANATION

p points to arr[0]. *p = 5 modifies arr[0]. Printing arr[0] displays 5.

Take Test
Q.122 Easy Pointers
What is the result of: int x = 5; int *p = &x; int *q = p; if p == q?
A 0 (false)
B 1 (true)
C Undefined
D Compiler error
Correct Answer:  B. 1 (true)
EXPLANATION

Both p and q point to same address of x, so p == q evaluates to true (1).

Take Test
Q.123 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.

Take Test
Q.124 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.

Take Test
Q.125 Easy Pointers
Which of the following correctly declares a pointer to a pointer?
A int **ptr;
B int *&ptr;
C int &&ptr;
D int ***ptr;
Correct Answer:  A. int **ptr;
EXPLANATION

Double pointer (int **ptr) is the correct syntax for pointer to pointer. Single & is used in C++ references, not C.

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

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

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

Take Test
Q.129 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.130 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
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