Home Tests Campus Placement

Campus Placement

Campus placement MCQ questions — Aptitude, Verbal, Reasoning, Technical.

2,162 Q 4 Subjects Any Graduate
Take Mock Test
Difficulty: All Easy Medium Hard 2161–2162 of 2,162
Advertisement
Q.2161 Easy Computer Knowledge
Which of the following correctly describes the difference between malloc() and calloc() in C?
A malloc() initializes memory to zero, calloc() does not
B calloc() initializes memory to zero and takes two arguments (number of elements and size), malloc() takes one argument and does not initialize
C malloc() is faster than calloc() but uses more memory
D calloc() can only allocate memory for arrays, malloc() can allocate for any data type
Correct Answer:  B. calloc() initializes memory to zero and takes two arguments (number of elements and size), malloc() takes one argument and does not initialize
EXPLANATION

The answer is correct because it accurately captures the fundamental distinction between these two memory allocation functions in C. malloc() allocates a block of uninitialized memory and requires only the total number of bytes as a single argument, while calloc() allocates memory for an array of elements, takes two arguments (number of elements and size per element), and crucially initializes all allocated memory to zero. This initialization feature of calloc() is a key advantage when you need guaranteed zero values, whereas malloc() leaves memory with whatever garbage values were previously there. Other options would be incorrect if they claimed malloc() initializes memory, if they stated calloc() takes only one argument, or if they reversed which function initializes to zero.

Take Test
Q.2162 Medium Computer Knowledge
What will be the output of the following C code?

int main() {
int x = 5;
int *p = &x;
int **q = &p;
printf("%d", **q + 1);
return 0;
}
A 6
B 5
C Compilation error
D Garbage value
Correct Answer:  A. 6
EXPLANATION

The correct answer is 6 because q is a pointer to pointer that points to p, which points to x. When we dereference q, we get the value of x (which is 5), and then adding 1 gives us 6, which is printed. The key concept here is understanding pointer dereferencing: a single asterisk dereferences one level, so double asterisks dereference two levels, bringing us from q to p to the actual value stored in x. Any other answer would be incorrect because it would either misunderstand the double dereferencing operation or incorrectly interpret what value is being accessed—for instance, if someone only dereferenced once or forgot to add 1, they would get a different result.

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