C++ Basics
MATLAB Basics
Debugging C++
Debugging MATLAB
File Handling & Data Structures
Logical & Control Flow
100

What is the correct syntax to declare an integer variable named num in C++?

int num;


100

What is the default numeric data type in MATLAB?

double

100

What will happen if you forget to initialize a pointer before dereferencing it in C++?

It leads to undefined behavior, possibly causing a segmentation fault.

100

What MATLAB command stops execution at the first error?

dbstop if error

100

Which C++ library is required for file handling?

#include <fstream>

100

What type of loop ensures execution at least once in C++?

do-while

200

What is the purpose of the #include <iostream> statement in C++?

It allows the program to use input and output functions like cout and cin.

200

What will be the output of the following MATLAB code?

2 3 (A 2-row, 3-column matrix)

200

Why does the following C++ program cause an error?

The variable num is used before being initialized, leading to undefined behavior.

200

Why does this MATLAB script fail?

Variable y is undefined.

200

How do you check if a file exists in MATLAB before opening it?

isfile('filename.txt')

200

What does the MATLAB function mod(5,2) return?

1 (Remainder of 5 / 2)

300

What will be the output of the following C++ code? 

11 (Multiplication has higher precedence than addition: 4 * 2 + 3 = 11).

300

What does the : operator do in MATLAB when used like this?



Creates a vector [1 3 5 7 9], where 1 is the start, 2 is the step size, and 10 is the end limit.

300

What is wrong with this C++ loop?

The semicolon after while (i < 5); makes the loop do nothing, causing an infinite loop.

300

What will MATLAB return for the following?

 

An error: Index exceeds matrix dimensions.

300

How do you append text to a file in MATLAB?

Use fopen('file.txt', 'a')

300

What will be the output of this MATLAB loop? 

Prints 1 3 5.

400

What is the difference between endl and \n in C++ when printing output?

Both create a new line, but endl also flushes the output buffer, which can slow performance.

400

What command would you use to display both variable values and their names in MATLAB?

whos

400

How can you use gdb to set a breakpoint at line 10 of main.cpp?

Run gdb a.out, then type break main.cpp:10.

400

What command lists all breakpoints in a MATLAB script?

dbstatus

400

Which function reads a line from a file in C++?

getline(ifstream, string)

400

What will be the output of this C++ loop? 

Hello Hello Hello

500

How does a switch statement differ from an if-else statement in C++?

A switch is more efficient when comparing a single variable to multiple constants because it uses jump tables, whereas if-else statements evaluate conditions sequentially.

500

What will the following MATLAB script display? 

[1 2 3] (Element-wise division)

500

Why does this C++ program crash?

Array index out of bounds error (arr[10] is out of range, valid indices are 0-9).

500

How do you remove all breakpoints from a MATLAB script?

dbclear all

500

What does the following MATLAB function do? 

It squares each element in x and adds 2.

500

What will the following MATLAB code output? 

0 0 1 1 (Boolean mask)

M
e
n
u