WorksheetsC++ Concepts Mastery
Total questions: 10
Worksheet time: 5mins
What are the basic data types in C++?
int, float, string, long, short
char, double, void, long, short
int, float, double, char, bool
string, array, void, long, short
Explain the difference between while and do-while loop in C++.
The while loop and do-while loop are the same and can be used interchangeably
The while loop checks the condition before executing the code inside the loop, while the do-while loop executes the code inside the loop at least once before checking the condition.
The while loop executes the code inside the loop at least once before checking the condition
The do-while loop checks the condition before executing the code inside the loop
What is the scope of a variable declared inside a function in C++?
Limited to the function in which it is declared
Accessible from any function in the program
Limited to the block in which it is declared
Accessible only from the main function
How can you open a file in C++ for writing?
ofstream myfile("example.txt");
openfile myfile('example.txt');
ofstream myfile = open('example.txt');
writefile myfile('example.txt');
What is the purpose of the 'return' statement in a function in C++?
To pause the execution of the function
To exit the function and return a value to the calling code.
To print a message to the console
To skip the rest of the code in the function
What is the syntax for declaring a multi-dimensional array in C++?
arrayName[size1, size2, ..., sizeN] = dataType;
arrayName[size1][size2]...[sizeN];
dataType arrayName[size1][size2]...[sizeN];
dataType arrayName[size1, size2, ..., sizeN];
How can you read data from a file in C++?
Using the cin object to read from the file
Using the ifstream class and its member functions
Using the ofstream class and its member functions
Using the fstream class and its member functions
Explain the concept of function overloading in C++.
Function overloading in C++ allows multiple functions with the same name and same parameters to be defined within the same scope.
Function overloading in C++ allows only one function with a specific name to be defined within the same scope.
Function overloading in C++ allows multiple functions with different names but same parameters to be defined within the same scope.
Function overloading in C++ allows multiple functions with the same name but different parameters to be defined within the same scope.
What is the use of 'break' statement in C++?
To terminate the loop or switch statement and transfer the control to the next statement after the loop or switch.
To create a new variable
To print a message on the screen
To add two numbers together
How can you close a file in C++?
end()
shut()
stop()
close()
