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 231–240 of 499
Topics in C Programming
Q.231 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.

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

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

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

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

Take Test
Q.236 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.237 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.238 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.239 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.240 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
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