Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 241–250 of 499
Topics in C Programming
Q.241 Medium Pointers
Consider the code: int arr[] = {5, 10, 15, 20}; int *ptr = arr; ptr++; What does ptr now point to?
A The value 5
B The value 10
C The address of arr[1]
D The address increased by 1 byte
Correct Answer:  C. The address of arr[1]
EXPLANATION

Pointer arithmetic increments by the size of the data type. For int (4 bytes), ptr++ moves to the next integer, which is arr[1].

Take Test
Q.242 Medium Pointers
A void pointer can be used to store addresses of variables of any data type. However, it must be cast before dereferencing. Which statement about void pointers is FALSE?
A void *p can store address of int, float, or char
B void *p can be directly dereferenced without casting
C void pointers are useful in generic functions like malloc()
D A void pointer must be cast to appropriate type for arithmetic operations
Correct Answer:  B. void *p can be directly dereferenced without casting
EXPLANATION

A void pointer cannot be directly dereferenced. It must be cast to the appropriate pointer type first.

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

arr[1] and *(p+1) both access the second element of the array, which is 20.

Take Test
Q.244 Medium Pointers
What is a dangling pointer?
A Pointer pointing to freed memory
B NULL pointer
C Uninitialized pointer
D Pointer declared outside main()
Correct Answer:  A. Pointer pointing to freed memory
EXPLANATION

A dangling pointer is a pointer that points to memory that has been freed or deallocated.

Take Test
Q.245 Medium Pointers
Which of the following correctly allocates memory for 10 integers?
A int *p = malloc(10);
B int *p = malloc(10 * sizeof(int));
C int *p = malloc(sizeof(int));
D int *p = alloc(10);
Correct Answer:  B. int *p = malloc(10 * sizeof(int));
EXPLANATION

malloc requires the size in bytes. For 10 integers, we need 10 * sizeof(int) bytes.

Take Test
Q.246 Medium Pointers
What is the output?
int *p = NULL;
if(p) printf("Not NULL");
else printf("NULL");
A Not NULL
B NULL
C Segmentation fault
D Compilation error
Correct Answer:  B. NULL
EXPLANATION

NULL pointer evaluates to false in a conditional, so the else block executes.

Take Test
Q.247 Medium Pointers
What is a wild pointer?
A Pointer pointing to NULL
B Uninitialized pointer with garbage address
C Pointer in a wildlife program
D Pointer declared inside a loop
Correct Answer:  B. Uninitialized pointer with garbage address
EXPLANATION

A wild pointer is an uninitialized pointer that contains an arbitrary/garbage memory address.

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

p+2 points to the third element of the array. *(p+2) dereferences it to get 3.

Take Test
Q.249 Medium Pointers
What is the output?
int x = 10, y = 20;
int *p = &x;
int *q = &y;
p = q;
printf("%d", *p);
A 10
B 20
C Address of y
D Garbage value
Correct Answer:  B. 20
EXPLANATION

After p = q, pointer p now points to y. So *p gives the value of y, which is 20.

Take Test
Q.250 Medium Pointers
What happens when you increment a pointer?
int arr[5] = {1,2,3,4,5};
int *p = arr;
p++;
A p points to the next byte in memory
B p points to the next element of the array
C p's value increases by 1
D Compilation error
Correct Answer:  B. p points to the next element of the array
EXPLANATION

When a pointer is incremented, it moves to the next element based on the data type size (pointer arithmetic).

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