wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Concepts Mastery

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What are the basic data types in C++?

a)

int, float, string, long, short

b)

char, double, void, long, short

c)

int, float, double, char, bool

d)

string, array, void, long, short

2.

Explain the difference between while and do-while loop in C++.

a)

The while loop and do-while loop are the same and can be used interchangeably

b)

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.

c)

The while loop executes the code inside the loop at least once before checking the condition

d)

The do-while loop checks the condition before executing the code inside the loop

3.

What is the scope of a variable declared inside a function in C++?

a)

Limited to the function in which it is declared

b)

Accessible from any function in the program

c)

Limited to the block in which it is declared

d)

Accessible only from the main function

4.

How can you open a file in C++ for writing?

a)

ofstream myfile("example.txt");

b)

openfile myfile('example.txt');

c)

ofstream myfile = open('example.txt');

d)

writefile myfile('example.txt');

5.

What is the purpose of the 'return' statement in a function in C++?

a)

To pause the execution of the function

b)

To exit the function and return a value to the calling code.

c)

To print a message to the console

d)

To skip the rest of the code in the function

6.

What is the syntax for declaring a multi-dimensional array in C++?

a)

arrayName[size1, size2, ..., sizeN] = dataType;

b)

arrayName[size1][size2]...[sizeN];

c)

dataType arrayName[size1][size2]...[sizeN];

d)

dataType arrayName[size1, size2, ..., sizeN];

7.

How can you read data from a file in C++?

a)

Using the cin object to read from the file

b)

Using the ifstream class and its member functions

c)

Using the ofstream class and its member functions

d)

Using the fstream class and its member functions

8.

Explain the concept of function overloading in C++.

a)

Function overloading in C++ allows multiple functions with the same name and same parameters to be defined within the same scope.

b)

Function overloading in C++ allows only one function with a specific name to be defined within the same scope.

c)

Function overloading in C++ allows multiple functions with different names but same parameters to be defined within the same scope.

d)

Function overloading in C++ allows multiple functions with the same name but different parameters to be defined within the same scope.

9.

What is the use of 'break' statement in C++?

a)

To terminate the loop or switch statement and transfer the control to the next statement after the loop or switch.

b)

To create a new variable

c)

To print a message on the screen

d)

To add two numbers together

10.

How can you close a file in C++?

a)

end()

b)

shut()

c)

stop()

d)

close()