wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

NNLT C++

Total questions: 61

Worksheet time: 3610secs

Name
Class
Date
1.

Thiếu dấu nháy kép (“) khi soạn thảo chương trình là lỗi gì?

a)

Cú pháp.

b)

Ngữ nghĩa.

c)

Không có lỗi.

d)

Lỗi sai NNLT

2.

Trong C++, hãy chọn câu đúng trong bài toán có 2 tên được đặt sau đây?

a)

1b , 2b

b)

BT , Bai tap

c)

bai*tap , bai_tap

d)

bt , BT

3.

Cho đoạn chương trình sau sau: int a,x,b;

cin>>a>>b>>x;

Tên nào là tên do người lập trình đặt?

a)

a và b

b)

a, b và x

c)

cin

d)

cout

4.

Bảng chữ cái của C++, khác với Pascal là có sử dụng thêm kí tự:

a)

dấu nháy đơn (')

b)

dấu sổ xuôi (/)

c)

dấu sổ ngược (\)

d)

không thêm kí tự nào

5.

Trong C++, “từ khóa” dùng để chỉ?

a)

Tên

b)

Tên dành riêng

c)

Tên chuẩn

d)

Tên do người lập trình đặt

6.

“iostream” là loại tên gì trong C++?

a)

Tên thường.

b)

Tên dành riêng.

c)

Tên chuẩn.

d)

Tên do người lập trình đặt.

7.
The process of creating a new variable without value
a)
declaration
b)
naming
c)
instantiation
d)
assigning
8.

What does <= mean?

a)

less than

b)

greater than

c)

less than or equal to

d)

greater than or equal to

9.

What is the only function all C++ programs must contain?

a)

start()

b)

system()

c)

main()

d)

program()

10.

What punctuation is used to signal the beginning and end of code blocks?

a)

{ }

b)

-> and <-

c)

BEGIN and END

d)

( and )

11.

Which of the following is a correct comment?

a)

*/ Comments */

b)

** Comment **

c)

/* Comment */

d)

{ Comment }

12.
The process of creating a new variable without value
a)
declaration
b)
naming
c)
instantiation
d)
assigning
13.

What does <= mean?

a)

less than

b)

greater than

c)

less than or equal to

d)

greater than or equal to

14.
A list of instructions that enable a computer to perform a specific task is a...
a)
Computer Program
b)
Algorithm
c)
Machine Code
d)
Binary Code
15.
Which command moves the shown text to the next line?
a)
\t
b)
\n
c)
\r
d)
\s
16.
After running the following code, what will be the value of x?
y = 3;
x = 5 * y;
a)
3
b)
5
c)
15
d)
0
17.
A programmer is:
a)
person who writes code and communicates instructions to a computer
b)
person who types
c)
person who studies computers
d)
error or mistake in your code
18.
What is the output of this program?
Program
int main()
{
cout<<"Hi everybody";
return 0;
}
a)
"Hi everybody"
b)
Hi everybody"
c)
Hi everybody
d)
"Hi everybody
19.
... variables store whole numbers (-4, 3, 51, etc). 
a)
Float
b)
Logical
c)
Character
d)
Integer
20.
... point variables store decimal numbers (3.5, -5,123, 4.0, etc). 
a)
Float
b)
Integer
c)
Logical
d)
Character
21.

Which of the following is NOT a logical operator in C++ language?

a)

&

b)

&&

c)

||

d)

!

22.

Which of the following is NOT a comparison operator in C++ language?

a)

>

b)

<=

c)

=

d)

==

23.

Evaluate the following expressions to true or false


3!=4-1

a)

true

b)

False

24.

Evaluate the following expressions to true or false


5 >= (1+6)-4

a)

True

b)

False

25.

Evaluate the following expressions to true or false

5+1==6 || 8-1>4

a)

True

b)

False

26.

If originally x=2,y=0, and z=1, what is the value of x, y, and z after executing the following code?


if (x>y)


y=x;

else

z=x;

a)

x=2 y=2 z=1

b)

x=0 y=2 z=0

c)

x=2 y=1 z=1

d)

x=2 y=0 z=1

27.

If-else

a)

Optional value for the program to execute

b)

Is a condition followed by a statement or a set of statements

c)

Is a statement followed by a condition or a set of conditions

d)

Function with a value

28.

What happens if an exception is thrown in a function, but not caught?

a)

The program continues executing and it is ignored.

b)

The function that throws the exception is exited.

c)

The program terminates.

d)

The compiler will find the error and the program would not compile.

29.

What is the difference between an array and STL, Standard Template Library, array?

a)

They are the same thing.

b)

STL array is a dynamic array

c)

Array size must be known at compile time but, STL array size does not.

d)

Array is a data structure and STL array is an instance of a class.

30.

There can only be one catch block in a program

a)

True

b)

False

31.

The compiler creates an instance of a function template in memory as soon as it encounters the template.

a)

True

b)

False

32.

When a class becomes a friend of another class they are additionally getting access to:

a)

Private

b)

Protected

c)

Public

d)

None of the above

33.

When a class is derived from a base class it gets access to:

a)

Private

b)

Protected

c)

Private and Protected

d)

Protected and Public

e)

Private, Protected and Public

34.

In a class the access specifiers are _______ by default:

a)

Private

b)

Protected

c)

Public

35.

What does the word const do when placed at the end of a member function in a class?

a)

It is required for C++

b)

States the return type is constant

c)

States the input arguments are constant

d)

States the member variables will not change

e)

None of the above

36.
a)

Equal strings

b)

There will be a compile error and it will not run

c)

Nothing will be output on the console

d)

None of the above

37.
a)

I only

b)

II only

c)

III only

d)

I and II only

e)

II and II only

38.

When class B is inherited from class A, what is the order in which the destructors are called.

a)

Class A first Class B next

b)

Class B first Class A next

c)

Class B's only as it is the child class

d)

Class A's only as it is the parent class

39.

What does the word virtual do when placed in front of a member function in C++?

a)

Forces derived classes to define the function to compile.

b)

Allows derived classes, not required, to define the function.

c)

Does not place the function in text segment if it is not called.

d)

None of the above.

40.

What happens if the word static is placed in front of a member function in C++?

a)

The member function can be called even if we do not create an instance of the class.

b)

It places the member function in the static part of memory

c)

It will cause an error and the program will not compile.

d)

None of the above.

41.

When overloading a function, the signature of the function is determined by:

a)

The name of the function

b)

The name of the function and number of argument and types

c)

The return type, name and number of arguments and types.

42.
a)

The derived class can not call the base class func().

b)

Must place “using namespace Base” at the top of the file.

c)

Base::d.func();

d)

d.Base::func();

43.
a)

1

b)

6

c)

12

d)

24

44.

What is the difference when allocating the following memory?

int array1[15];

int array2[3][5];

a)

array1 is larger

b)

array2 is larger

c)

The size allocated is the same

45.
a)

1

b)

2

c)

4

d)

8

46.
a)

0

b)

5

c)

-5

d)

10

e)

-10

47.
a)

0

b)

1

c)

2

d)

3

e)

There are two count variables. Not enough info

48.
a)

Compile Error

b)

Inside Fun1()

c)

Inside Fun2()

d)

Inside Fun1() Inside Fun2()

e)

Inside Fun2() Inside Fun1()

49.
a)

Inside try

Exception Caught

After throw

After catch

b)

Inside try

Exception Caught

After catch

c)

Inside try

Exception Caught

d)

Inside try

After throw

After catch

50.

A function can have _____ inside the parenthesis

a)

loops

b)

Arguments/Parameters

c)

Braces

d)

Types

51.

A function that has no return type starts with:

a)

int

b)

void

c)

Arguments

d)

Braces

52.

A function that returns a whole number starts with the word

a)

int

b)

void

c)

string

d)

{ }

53.

Fill in the blank to have this function work properly


_____ function ( ) {


int a = 4;

int b = 5;


cout<<a*b;


}

a)

string

b)

int

c)

void

d)

variable

54.

Fill in the blank to have this function work properly


_____ function ( ) {


string greeting = "Welcome to my game";


return greeting;


}

a)

string

b)

void

c)

int

d)

variable

55.

Fill in the blank to have this function work properly


_____ function ( ) {


int a;

cin >> a;


cout<<"You chose " << a <<endl;


}

a)

string

b)

void

c)

int

d)

variable

56.

True or False. We can call functions inside of other functions.

a)

True

b)

False

57.

True or False. A function that returns a string starts with the word void.

a)

True

b)

False

58.

Select all of the types you may have for a function

a)

string

b)

bool

c)

void

d)

variable

e)

int

59.

A function that is not void needs to have a _____ _______

a)

variable calculation

b)

printing statement

c)

Return statement

d)

cout statement

60.

Fill in the blank to have this function work properly


double function ( ) {


int a;

cin >> a;


cout<<"You chose " << a <<endl;


return ____ ;


}

a)

"a"

b)

a

c)

a * 3.14

d)

cin

61.

Choose a right C Statement.

a)

Loops or Repetition block executes a group of statements repeatedly.

b)

Loop is usually executed as long as a condition is met.

c)

Loops usually take advantage of Loop Counter

d)

All the above.