0% found this document useful (0 votes)
5 views7 pages

C++ and Java Programming Concepts Quiz

The document contains a set of conceptual and programming questions related to C++ and Java, covering topics such as object slicing, OOP principles, exception handling, and recursion. It also includes aptitude questions that require mathematical reasoning and pattern recognition. The questions are categorized into easy, medium, and hard levels, with varying point values assigned to each.

Uploaded by

riduvarshinias
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

C++ and Java Programming Concepts Quiz

The document contains a set of conceptual and programming questions related to C++ and Java, covering topics such as object slicing, OOP principles, exception handling, and recursion. It also includes aptitude questions that require mathematical reasoning and pattern recognition. The questions are categorized into easy, medium, and hard levels, with varying point values assigned to each.

Uploaded by

riduvarshinias
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Set 2

Inverse coding - Round 1 (Set B)

Conceptual questions - 10 (1 point)


Easy :
1. In C++, which of these can lead to "Object Slicing"?
A) Assigning a derived class object to a base class variable by value.
B) Using a smart pointer (std::unique_ptr) for polymorphic objects.
C) Overloading an operator in a base class.
D) Implementing a virtual destructor in the base class.

2..Which OOP principle ensures that a class hides its internal details and only exposes necessary
functionality?
A) Abstraction
B) Polymorphism
C) Inheritance
D) Encapsulation

[Link] a C++ program, which of the following constructors is automatically invoked when an object is
passed by value to a function?
A) Copy Constructor
B) Default Constructor
C) Parameterized Constructor
D) Move Constructor

[Link] of the following best describes a deep copy in C++?


A) Copying only the address of the object.
B) Copying the contents of the object, including dynamic memory, to a new object.
C) Copying only the object’s values, not its pointers.
D) Copying only the pointer to the object, leaving the data unmodified.

[Link] of the following algorithms is used to find the shortest path in a weighted graph with
non-negative edges?
A) Bellman-Ford Algorithm
B) Dijkstra's Algorithm
C) Floyd-Warshall Algorithm
D) Prim's Algorithm

Medium :
6. Given an array where all elements except one appear twice, which methods can find the unique
element in O(n) time and O(1) space?
A) XOR-ing all elements together
B) Sorting and then checking adjacent elements
C) Using stack to track the unique elements
D) Using a HashMap to count occurrences
7. In Java, which of the following statements about exception handling are false?
A) Checked exceptions must be handled explicitly in Java
B) finally always executes, even if an exception is thrown
C) throw and throws mean the same thing
D) A method overriding another method cannot throw broader exceptions

8. What is the fastest way to compute the Nth Fibonacci number (F(N))?
A) Recursion
B) Dynamic Programming
C) Matrix Exponentiation
D) Binet’s Formula

Hard :
9. Which of the following scenarios result in undefined behavior (UB) in C++?
A) Modifying a variable multiple times in a single statement without a sequence point
B) Accessing a pointer after calling free() on it
C) Using std::vector with at() to access an out-of-bounds index
D) Using memcpy() to copy overlapping memory regions.

10.A real-time multiplayer game server needs to efficiently handle hundreds of thousands of
concurrent players. It must support rapid state updates, spatial queries (e.g., finding nearby players),
and load balancing across multiple regions. Which data structure would be the most optimal for
managing dynamic player positions and interactions?
A) Quad-tree with Lazy Updates​
B) Distributed Hash Table (DHT) with Proximity Awareness​
C) KD-Tree with Periodic Rebalancing​
D) Skip Graph with Spatial Partitioning

Program questions - 5 (2 points)


Look at the following C Program and answer the following questions:

void recursiveFunc(int *p, int n) {​


​ static int y = 1;​
​ if (n > 0) {​
​ *p += y;​
​ y += 1;​
​ recursiveFunc(p, n - 1);​
​ }​
}​

int main() {​
​ int x = 0;​
​ recursiveFunc(&x, 5);​
​ printf("Final X : %d\n", x);​
​ return 0;​
}
1)​ What is the final value of X?

A)​ 6
B)​ 10
C)​ 15
D)​ 20

2) What is the recursive relation that describes the recursive function?

A)​ T(n) = T(n−1) + n with T(0) = 0


B)​ T(n) = T(n−1) + 1 with T(0) = 0
C)​ T(n) = T(n−1) + (n−1) with T(0) = 0
D)​ T(n) = n + T(n−1) with T(1) = 1

Look at the following C Program and answer the following questions:

void function()​
{​
​ int *ptr = (int *)malloc(sizeof(int) * 5);​
​ ptr[0] = 10;​
​ ptr[1] = 20;​
​ ptr[2] = 30;​
​ ptr[3] = 40;​
​ ptr[4] = 50;​
50​
​ for (int i = 0; i <= 5; i++)​
​ {​
​ printf("ptr[%d] = %d\n", i, ptr[i]);​
​ }​

​ free(ptr);​
}​

int main()​
{​
​ function();​
​ return 0;​
}

3) What would be the last line of the output?

A)​ 60
B)​ 50
C)​ Segmentation Fault
D)​ Garbage value

4) What will be the output of the following Java Program?

public class Main {​


​ public static void main(String[] args) {​
​ try {​
​ int[] arr = new int[5];​
​ for (int i = 0; i <= 5; i++) {​
​ arr[i] = i * 10;​
​ }​
​ try {​
​ int result = arr[2] / 0;​
​ [Link]("Result: " + result);​
​ } catch (ArithmeticException e) {​
​ [Link]("ArithmeticException caught: Division by zero");​
​ }​
​ } catch (ArrayIndexOutOfBoundsException e) {​
​ [Link]("ArrayIndexOutOfBoundsException caught: Array index out of
bounds");​
​ } finally {​
​ [Link]("Outer finally block executed");​
​ }​
​ [Link]("Program continues...");​
​ }​
}

A)
ArithmeticException caught: Division by zero
Outer finally block executed

Program continues…

B)
ArrayIndexOutOfBoundsException caught: Array index out of bounds
Outer finally block executed
Program continues…

C)
ArithmeticException caught: Division by zero
Program continues…

D)
ArrayIndexOutOfBoundsException caught: Array index out of bounds
Program continues...

5) What would be the output of the following Java program?​


class Main {​
​ public static String getString() {​
​ String str = "Hello";​
​ return [Link]();​
​ }​

​ public static void main(String[] args) {​
​ String s = "";​
​ [Link](getString());​
​ [Link](s);​
​ }​
}

A)​ No Output and no errors


B)​ HELLO
C)​ Null Pointer Exception during runtime
D)​ Compilation error due to concat()

Aptitude questions - 5 (1 point)


[Link] x+2y=9 , then find 3x+6y.

2.A and B start a 200-meter race at the same time. A runs at 10 m/s, and B runs at 8 m/s. By how
many seconds will A beat B?
(A) 2.5 sec
(B) 4 sec
(C) 5 sec
(D) 6 sec

3. Select the odd figure out of the following figures :

A) 5
B) 3
C) 4
D) 1

[Link] : Light :: Echo : ?


(A) Sound
(B) Voice
(C) Reflection
(D) Whisper

[Link] at the series: 24, 6, 18, 9, 36, 9, 24, x


Find the value of x?

You might also like