C Programming — Pointers
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 71–80 of 100 questions in Pointers
Q.71 Medium Pointers
A function needs to modify a variable in the calling function. Which parameter passing method is appropriate?
A Pass by value
B Pass by reference using pointers
C Pass by global variable
D None of the above
Correct Answer:  B. Pass by reference using pointers
EXPLANATION

To modify a variable in the calling function, you must pass its address (pointer). Pass by value creates a copy and cannot modify the original.

Take Test
Q.72 Medium Pointers
Consider: int arr[5] = {1, 2, 3, 4, 5}; int *p = arr; What is the value of *(p+2)?
A 2
B 3
C 4
D 5
Correct Answer:  B. 3
EXPLANATION

p points to arr[0]. p+2 points to arr[2], and *(p+2) dereferences to the value at arr[2], which is 3.

Take Test
Q.73 Medium Pointers
Which memory allocation function does NOT initialize allocated memory to zero?
A calloc()
B malloc()
C realloc()
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

malloc() and realloc() return uninitialized memory with garbage values. calloc() initializes all bytes to zero.

Take Test
Q.74 Medium Pointers
Consider: int x = 5; int *p = &x; int **q = &p; What is the value of **q?
A 5
B Address of p
C Address of x
D Error
Correct Answer:  A. 5
EXPLANATION

q is a pointer to pointer p. **q dereferences twice: first to get p, then to get the value x, which is 5.

Take Test
Q.75 Medium Pointers
Which of the following best describes a dangling pointer situation?
A A pointer that points to a valid memory location
B A pointer that points to memory that has been freed or deallocated
C A pointer that has not been initialized
D A pointer used in arithmetic operations
Correct Answer:  B. A pointer that points to memory that has been freed or deallocated
EXPLANATION

A dangling pointer occurs when it points to memory that no longer exists, typically after free() or when a local variable goes out of scope.

Take Test
Q.76 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.77 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.78 Easy Pointers
What will be printed by the code: char *ptr = "Hello"; printf("%c", *ptr);
A H
B Hello
C e
D Error
Correct Answer:  A. H
EXPLANATION

ptr points to the first character of the string, so *ptr dereferences to 'H'. The %c format specifier prints a single character.

Take Test
Q.79 Easy Pointers
Which operator is used to get the address of a variable?
A * (asterisk)
B & (ampersand)
C -> (arrow)
D . (dot)
Correct Answer:  B. & (ampersand)
EXPLANATION

The & (address-of) operator returns the memory address of a variable.

Take Test
Q.80 Easy Pointers
Consider: int x = 10; int *p = &x; What does the expression *p represent?
A The address of x
B The pointer variable p
C The value stored in x
D The size of x
Correct Answer:  C. The value stored in x
EXPLANATION

The dereference operator (*) accesses the value at the address pointed to by p, which is the value 10.

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