Home Subjects C Programming Pointers

C Programming
Pointers

C language from basics to advanced placement prep

51 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 51
Topics in C Programming
Q.31 Medium Pointers
What does calloc() do that malloc() doesn't?
A Allocates more memory
B Initializes allocated memory to zero
C Allocates memory faster
D Returns a void pointer
Correct Answer:  B. Initializes allocated memory to zero
EXPLANATION

calloc() takes two parameters (number of elements, size) and initializes all bytes to zero, while malloc() leaves memory uninitialized.

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

p points to a[0], p+2 points to a[2] which contains 30. Dereferencing gives 30.

Test
Q.33 Medium Pointers
What is the difference between pointer and array name in C?
A No difference, both are same
B Array name is a pointer constant, cannot be modified
C Pointer can store any address, array name stores only array address
D Arrays are faster than pointers
Correct Answer:  B. Array name is a pointer constant, cannot be modified
EXPLANATION

Array names are pointer constants that point to the first element and cannot be reassigned, while pointer variables can be modified to point to different addresses.

Test
Q.34 Medium Pointers
What will be the output of: int x = 10; int *p = &x; printf("%p", p); (assuming typical system output)
A 10
B A memory address in hexadecimal format
C The size of integer
D Error: invalid format specifier
Correct Answer:  B. A memory address in hexadecimal format
EXPLANATION

The %p format specifier prints the pointer value as a memory address in hexadecimal format, not the dereferenced value.

Test
Q.35 Medium Pointers
Consider: void func(int *arr, int size); This function prototype suggests that func will:
A Create a new array inside the function
B Modify the original array passed from the caller
C Only read the array values
D Return the array to the caller
Correct Answer:  B. Modify the original array passed from the caller
EXPLANATION

Since an array pointer is passed, the function can access and modify the original array elements in the caller's scope.

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

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

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

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

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

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