Home Tests Campus Placement

Campus Placement

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

1,016 Q 4 Subjects Any Graduate
Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1011–1016 of 1,016
Subjects in Campus Placement
Q.1011 Medium Computer Knowledge C Programming
What is the difference between scanf() and gets() functions?
A scanf() can read formatted input while gets() reads only strings
B gets() is safer than scanf()
C There is no difference
D scanf() stops at whitespace while gets() doesn't
Correct Answer:  A. scanf() can read formatted input while gets() reads only strings
EXPLANATION

scanf() reads formatted input based on format specifiers and stops at whitespace. gets() reads a string until a newline is encountered. Note: gets() is deprecated due to buffer overflow vulnerabilities.

Take Test
Q.1012 Medium Computer Knowledge C Programming
What is the output of the following C code?
int x = 5;
int y = ++x + x++;
printf("%d", y);
A 11
B 12
C 13
D Undefined behavior
Correct Answer:  D. Undefined behavior
EXPLANATION

This code exhibits undefined behavior because x is modified twice between sequence points without an intervening sequence point. The result depends on the compiler's implementation.

Take Test
Q.1013 Medium Computer Knowledge
Which data structure is most suitable for implementing a priority queue where elements with higher priority need to be dequeued first?
A Array
B Linked List
C Min-Heap or Max-Heap
D Graph
Correct Answer:  C. Min-Heap or Max-Heap
EXPLANATION

A Heap (either Min-Heap or Max-Heap) is the optimal data structure for implementing priority queues with O(log n) insertion and deletion time complexity.

In a Max-Heap, the element with the highest priority is always at the root, enabling efficient extraction of the maximum element.

Arrays and Linked Lists would require O(n) time for priority-based operations, while Graphs are unsuitable for this purpose.

Heaps are fundamental in algorithms like Dijkstra's and Prim's for finding shortest paths.

Take Test
Q.1014 Medium Computer Knowledge
Which of the following operations has an average time complexity of O(1) in a Hash Table with good hash function and low collision rate?
A Insertion only
B Search only
C Both insertion and search
D Deletion only
Correct Answer:  C. Both insertion and search
EXPLANATION

Hash Tables achieve O(1) average-case time complexity for both insertion and search operations when using a well-designed hash function that minimizes collisions and maintains a good load factor.

Deletion also operates in O(1) average time.

However, in worst-case scenarios with poor hash functions or high collision rates, these operations can degrade to O(n).

The key to performance is maintaining low collision rates through techniques like chaining or open addressing.

Take Test
Q.1015 Medium Computer Knowledge
What is the output of the following code snippet?

int main() {
char arr[] = "GATE";
char *p = arr;
printf("%d\n", sizeof(arr));
printf("%d", sizeof(p));
return 0;
}
A 4 and 4
B 5 and 4
C 5 and 8 (on 64-bit system)
D 4 and 8 (on 64-bit system)
Correct Answer:  C. 5 and 8 (on 64-bit system)
EXPLANATION

The output is 5 and 8 because sizeof(arr) returns 5 bytes (4 characters plus 1 null terminator in the string "GATE"), while sizeof(p) returns 8 bytes on a 64-bit system since p is a pointer variable and pointers occupy 8 bytes in 64-bit architecture. The key concept is that sizeof() behaves differently for arrays versus pointers: when applied to an array, it returns the total memory allocated for the entire array, but when applied to a pointer, it only returns the size of the pointer itself, not what it points to. Other options would be incorrect because they either miscalculate the array size by forgetting the null terminator, use incorrect pointer sizes (like 4 bytes for 32-bit systems), or confuse the size of the array with the size of the pointer variable.

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