0% found this document useful (0 votes)
22 views17 pages

MIT Mock InterviewQuestions

The document contains mock interview questions and answers for various programming languages including C, C++, Java, Python, SQL, and topics related to data structures and algorithms. It covers fundamental concepts such as memory management, object-oriented programming, and embedded systems, providing clear explanations and examples. Additionally, it includes practical coding tasks and comparisons between different programming constructs.
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)
22 views17 pages

MIT Mock InterviewQuestions

The document contains mock interview questions and answers for various programming languages including C, C++, Java, Python, SQL, and topics related to data structures and algorithms. It covers fundamental concepts such as memory management, object-oriented programming, and embedded systems, providing clear explanations and examples. Additionally, it includes practical coding tasks and comparisons between different programming constructs.
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
You are on page 1/ 17

Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

C Programming Mock Interview Questions

1. What is the difference between ++i and i++?

Answer:​
++i is pre-increment: increments the value and returns the incremented value.​
i++ is post-increment: returns the original value, then increments.

int i = 5;
printf("%d", ++i); // 6
printf("%d", i++); // 6 (then becomes 7)

2. What is a dangling pointer?

Answer:​
A pointer pointing to a memory location that has been freed or deleted is called a dangling pointer.

3. Difference between malloc() and calloc()?

Answer:

●​ malloc() allocates memory but does not initialize it.​

●​ calloc() allocates and initializes all bits to zero.​

4. What is the output?

int x = 10;
printf("%d %d %d", x++, ++x, x++);

Answer: Output is undefined (compiler-dependent). Because the variable x is being modified more
than once between sequence points.

5. Can a const variable be modified in C?

Answer:​
By standard, const variables can't be modified. But using pointer tricks, it is possible (not
recommended).

Ethnus | www.ethnus.com | www.codemithra.com

©Page 1
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

6. What is the difference between typedef and #define?

Answer:

●​ typedef is used to define new type names.​

●​ #define is a preprocessor directive for constants or macros.​

typedef unsigned int ui; // ui can now be used as an alias

#define PI 3.14 // replaces PI with 3.14 before compilation

7. What is a static variable in C?

Answer:​
A static variable retains its value between function calls and has internal linkage (limited to file
scope).

8. Difference between call by value and call by reference?

Answer:

●​ Call by value: copy of actual argument is passed, original is not modified.​

●​ Call by reference: address of variable is passed, original value can be modified.​

9. What is recursion? Give an example.

Answer:​
Recursion is when a function calls itself.​
Example:

int factorial(int n) {

if(n==0) return 1;

return n * factorial(n-1);

Ethnus | www.ethnus.com | www.codemithra.com

©Page 2
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

Write a C function to reverse a number.

int reverse(int num) {


int rev = 0;
while(num > 0) {
rev = rev * 10 + num % 10;
num = num / 10;
}
return rev;
}

✅ C++ Programming Mock Interview Questions


1. What is the difference between struct and class in C++?

Answer:

●​ struct members are public by default.​

●​ class members are private by default.​

2. What is a virtual function?

Answer:​
A function declared with the virtual keyword in a base class and overridden in the derived class,
allowing runtime polymorphism.

3. Explain Constructor Overloading.

Answer:​
Multiple constructors with different parameter lists in the same class. Example:

class Demo {
public:
Demo() {}
Demo(int x) {}
Demo(int x, int y) {}
};

4. What is a pure virtual function?

Ethnus | www.ethnus.com | www.codemithra.com

©Page 3
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

Answer:​
A virtual function with = 0, making the class abstract.

class Shape {
public:
virtual void draw() = 0;
};

5. What is the output?

class A {
public:
A() { cout << "A"; }
~A() { cout << "a"; }
};
class B {
public:
B() { cout << "B"; }
~B() { cout << "b"; }
};

int main() {
A a;
B b;
}

Answer: Output: ABba (Constructors are called in order of declaration, destructors in reverse order)

6. What is the difference between compile time and runtime polymorphism?

Answer:

●​ Compile-time: Function/Operator overloading.​

●​ Run-time: Virtual functions and method overriding.​

7. What are friend functions?

Answer:​
Friend functions can access private and protected members of a class.

class A {

Ethnus | www.ethnus.com | www.codemithra.com

©Page 4
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

private: int x = 10;

friend void show(A);

};

void show(A a) {

cout << a.x;

8. What is the use of this pointer?

Answer:​
It is an implicit pointer that refers to the current object of a class.

9. What is the difference between shallow copy and deep copy?

Answer:

●​ Shallow Copy: Copies only references (pointer values).​

●​ Deep Copy: Creates a new object and copies actual content.

10. Print sum of all elements in a vector

#include <vector>
#include <iostream>
using namespace std;

int main() {
vector<int> v = {1, 2, 3, 4};
int sum = 0;
for (int i : v) sum += i;
cout << "Sum = " << sum;
}

Ethnus | www.ethnus.com | www.codemithra.com

©Page 5
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

Java Programming Mock Interview Questions

1. What is the difference between == and .equals() in Java?

Answer:

●​ == compares references (memory addresses).​

●​ .equals() compares object contents (logical equality).​

2. What is method overloading vs method overriding?

Answer:

●​ Overloading: Same method name, different parameters, same class.​

●​ Overriding: Same method name and parameters in child class.​

3. What is the output?

class A {
void show() { System.out.println("A"); }
}

class B extends A {
void show() { System.out.println("B"); }
}

public class Main {


public static void main(String[] args) {
A obj = new B();
obj.show();
}
}

Answer: B (due to runtime polymorphism)

4. Explain final, finally, and finalize.

Answer:

Ethnus | www.ethnus.com | www.codemithra.com

©Page 6
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

●​ final: keyword to mark constant, method that can't be overridden, or class that can't be
extended.​

●​ finally: block that always executes after try-catch.​

●​ finalize(): method called by garbage collector before object destruction.​

5. Can we override static methods?

Answer:​
No. Static methods belong to the class, not to objects. You can hide but not override them.

6. What are the access specifiers in Java?

Answer:

●​ private: accessible within class​

●​ default (no modifier): accessible within package​

●​ protected: within package + subclass outside package​

●​ public: accessible everywhere​

7. What is an interface? How is it different from abstract class?

Answer:

●​ Interface: 100% abstract, only method declarations (Java 7).​

●​ Abstract Class: Can have methods with or without body.​

interface Drawable {

void draw();

Ethnus | www.ethnus.com | www.codemithra.com

©Page 7
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

8. What is garbage collection in Java?

Answer:​
Automatic process by JVM to free up memory by destroying unused objects.

9. Explain Exception Hierarchy in Java.

Answer:

●​ Throwable is the parent class.​

○​ Error (e.g., OutOfMemoryError) – not meant to be handled.​

○​ Exception – can be caught.​

■​ Checked (IOException)​

■​ Unchecked (ArithmeticException, NullPointerException)​

10. What is multithreading in Java?

Answer:​
Multithreading allows concurrent execution of two or more threads (independent paths of execution)
to increase performance.

class MyThread extends Thread {

public void run() {

System.out.println("Running thread");

Java:

Program to check if a string is a palindrome

public class Palindrome {


public static void main(String[] args) {
String str = "madam", rev = "";
for(int i = str.length()-1; i >= 0; i--)
rev += str.charAt(i);

Ethnus | www.ethnus.com | www.codemithra.com

©Page 8
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

System.out.println(str.equals(rev) ? "Palindrome" : "Not Palindrome");


}
}

Data Structures & Algorithms (DSA) – 5 Questions

1. What is the time complexity of binary search?

Answer:​
Time complexity is O(log n) for sorted arrays.​
It halves the search space at each step.

2. How is a queue different from a stack?

Answer:

●​ Stack: Last In First Out (LIFO)​

●​ Queue: First In First Out (FIFO)​

Feature Stack Queue

Insert push enqueue

Delete pop dequeue

3. Write a function to check if a string is a palindrome.

Python Code:

def is_palindrome(s):
return s == s[::-1]

Usage:​
is_palindrome("madam") → True

4. What is the difference between BFS and DFS?

Answer:

Ethnus | www.ethnus.com | www.codemithra.com

©Page 9
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

●​ BFS: Level-order traversal, uses a queue, good for shortest path.​

●​ DFS: Depth-first, uses a stack/recursion, explores deeper first.​

5.What is the difference between a linked list and an array?


Feature Array Linked List

Memory Contiguous memory Non-contiguous


(nodes/objects)

Access Time O(1) (direct access) O(n) (sequential traversal)

Insertion/Deletio Costly (need to shift elements) Efficient (adjust pointers)


n

Size Fixed (unless dynamically Dynamic (grows as needed)


allocated)

✅ React – 3 Questions
1. What is a component in React?

Answer:​
A component is a reusable piece of UI, like a function or class returning JSX.​
Example:

function Hello() {
return <h1>Hello, World!</h1>;
}

2. What is the difference between state and props in React?

Answer:

Feature Props State

Mutability Read-only Mutable

Scope Passed from Managed within


parent component

Ethnus | www.ethnus.com | www.codemithra.com

©Page 10
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

Props: External inputs to components.​

State: Local data controlled inside a component.​

3. Explain useEffect hook with an example.

Answer:​
useEffect() runs side effects (like fetching data, timers).

useEffect(() => {
console.log("Component mounted");
}, []); // empty array = runs once

✅ Python – 8 Questions
1. What are Python's advantages in embedded systems?

Answer:

●​ Python is easy to write and read, speeding up development.​

●​ MicroPython and CircuitPython are lightweight implementations suitable for microcontrollers.​

●​ Great for prototyping hardware.​

●​ Rich libraries for GPIO, I2C, SPI, and UART (e.g., RPi.GPIO, machine, pyserial).​

2. Explain the difference between is and == in Python.

Answer:

Ethnus | www.ethnus.com | www.codemithra.com

©Page 11
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

●​ == compares values.​

●​ is compares object identity (memory address).​

a = [1, 2]
b = [1, 2]
print(a == b) # True
print(a is b) # False

3. How does Python handle memory management?

Answer:

●​ Uses reference counting and garbage collection.​

●​ Memory is allocated on the heap.​

●​ gc module can be used to tune collection.​

4. What are decorators? Where can they be used in embedded applications?

Answer:

●​ Decorators are functions that modify behavior of other functions or methods.​

●​ Useful in embedded systems for:​

○​ Logging​

○​ Execution time measurement​

○​ Access control for critical sections​

def logger(func):
def wrapper():
print("Starting function")
func()
print("Ending function")
return wrapper

@logger
def blink_led():
print("LED ON")

Ethnus | www.ethnus.com | www.codemithra.com

©Page 12
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

5. How do you handle real-time constraints in Python for embedded systems?

Answer:

●​ Python isn't real-time by default.​

●​ Use MicroPython or embedded C extensions for time-sensitive parts.​

●​ Use hardware timers, interrupts, and optimize using uasyncio (asynchronous I/O).

6. What are Python's mutable and immutable data types?

Answer:

Mutable Immutable

List, Dict, Int, Float, Str,


Set Tuple

7. What is list comprehension? Give an example.

Answer:​
A concise way to create lists.

squares = [x**2 for x in range(5)]


# Output: [0, 1, 4, 9, 16]

8. **What are *args and kwargs in Python?

Answer:

●​ *args: Variable number of positional arguments​

●​ **kwargs: Variable number of keyword arguments​

def demo(*args, **kwargs):


print(args, kwargs)

Ethnus | www.ethnus.com | www.codemithra.com

©Page 13
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

demo(1, 2, a=3, b=4)


# Output: (1, 2) {'a': 3, 'b': 4}

SQL Programming – 5 Mock Interview Questions

1. What is the difference between WHERE and HAVING clause?

Answer:

Clause Use With Filters Rows Based On Used With


Aggregation

WHERE Tables Individual rows ❌ No


HAVIN
G
GROUP BY
results
Aggregated data ✅ Yes
Example:

-- Use WHERE before grouping


SELECT department, COUNT(*)
FROM employees
WHERE salary > 30000
GROUP BY department
HAVING COUNT(*) > 5;

2. Write a query to fetch the second highest salary from the employees table.

Answer:

SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

Alternate (using LIMIT - MySQL):

SELECT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1;

Ethnus | www.ethnus.com | www.codemithra.com

©Page 14
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

3. What is the difference between INNER JOIN and LEFT JOIN?

Answer:

Join Type Returns

INNER Matching rows from both tables only


JOIN

LEFT JOIN All rows from left table + matching rows from right (or NULL if no
match)

Example:

SELECT a.name, b.department_name


FROM employees a
LEFT JOIN departments b
ON a.department_id = b.id;

4. What is a subquery? Write a nested subquery example.

Answer:​
A subquery is a query inside another query.

Example:

SELECT name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

Here, the inner query calculates the average salary, and the outer query selects employees with salary
above average.

5. How do you find duplicate records in a table?

Answer:

SELECT name, COUNT(*)


FROM employees

Ethnus | www.ethnus.com | www.codemithra.com

©Page 15
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

GROUP BY name
HAVING COUNT(*) > 1;

This groups by name and shows only those having more than 1 occurrence.

Embedded Systems – Mock Interview Questions with Answers

1. What is the difference between microprocessor and microcontroller?

Answer:

Feature Microcontroller Microprocessor

Components CPU + RAM + ROM + Only CPU


I/O

Application Embedded systems General-purpose


systems

Power Low High


consumption

2. Explain polling vs interrupts.

Answer:

●​ Polling: CPU continuously checks the status of a device.​

●​ Interrupt: Device signals CPU when it needs attention (more efficient).​

3. How do you interface a sensor like DHT11 or MPU6050 with a microcontroller using Python?

Answer:

Ethnus | www.ethnus.com | www.codemithra.com

©Page 16
Ethnus | Company Specific Training Program| Trinity Group of Institutes, Pune

●​ Use machine or Adafruit libraries (MicroPython/CircuitPython).​

import dht

import machine

sensor = dht.DHT11(machine.Pin(14))

sensor.measure()

print(sensor.temperature())

4. What is the role of RTOS in embedded systems?

Answer:

●​ RTOS ensures deterministic task scheduling.​

●​ Handles multitasking, priority, timing, and resource management.​

●​ Used when Python is combined with firmware via dual-core MCUs (e.g., ESP32 with
MicroPython on one core, RTOS on another).​

5. What are some Python libraries used in embedded systems?

Answer:

●​ machine: For GPIO, PWM, ADC (MicroPython)​

●​ uasyncio: Lightweight async I/O​

●​ time: For delays, timestamps​

●​ pyserial: Serial communication with embedded devices​

●​ Adafruit_BBIO, RPi.GPIO: Raspberry Pi GPIO​

Ethnus | www.ethnus.com | www.codemithra.com

©Page 17

You might also like