What is the correct syntax to declare an integer variable named num in C++?
int num;
What is the default numeric data type in MATLAB?
double
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.
What MATLAB command stops execution at the first error?
dbstop if error
Which C++ library is required for file handling?
#include <fstream>
What type of loop ensures execution at least once in C++?
do-while
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.
What will be the output of the following MATLAB code?
2 3 (A 2-row, 3-column matrix)
Why does the following C++ program cause an error?
The variable num is used before being initialized, leading to undefined behavior.
Why does this MATLAB script fail?
Variable y is undefined.
How do you check if a file exists in MATLAB before opening it?
isfile('filename.txt')
What does the MATLAB function mod(5,2) return?
1 (Remainder of 5 / 2)
What will be the output of the following C++ code?
11 (Multiplication has higher precedence than addition: 4 * 2 + 3 = 11).
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.
What is wrong with this C++ loop?
The semicolon after while (i < 5); makes the loop do nothing, causing an infinite loop.
What will MATLAB return for the following?
An error: Index exceeds matrix dimensions.
How do you append text to a file in MATLAB?
Use fopen('file.txt', 'a')
What will be the output of this MATLAB loop?
Prints 1 3 5.
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.
What command would you use to display both variable values and their names in MATLAB?
whos
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.
What command lists all breakpoints in a MATLAB script?
dbstatus
Which function reads a line from a file in C++?
getline(ifstream, string)
What will be the output of this C++ loop?
Hello Hello Hello
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.
What will the following MATLAB script display?
[1 2 3] (Element-wise division)
Why does this C++ program crash?
Array index out of bounds error (arr[10] is out of range, valid indices are 0-9).
How do you remove all breakpoints from a MATLAB script?
dbclear all
What does the following MATLAB function do?
It squares each element in x and adds 2.
What will the following MATLAB code output?
0 0 1 1 (Boolean mask)