wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Worksheet

Total questions: 40

Worksheet time: 20mins

Name
Class
Date
1.

Which data type do we use to store a single letter?

a)

int

b)

char

c)

float

d)

string

2.

Which command prints the text "Hello" on the screen?

a)

cout << "Hello";

b)

cin >> "Hello";

c)

print("Hello");

d)

echo "Hello";

3.

Which command inputs an integer into the variable x?

a)

cin >> x;

b)

cout << x;

c)

input(x);

d)

scanf("%d", x);

4.

Which data type do we use for whole numbers?

a)

int

b)

float

c)

char

d)

string

5.

Which data type do we use for decimal numbers?

a)

int

b)

float

c)

char

d)

bool

6.

Which command adds 1 to the variable x?

a)

x = x + 1;

b)

x = x - 1;

c)

x * 1;

d)

x / 1;

7.

Which command prints the string s?

a)

cout << s;

b)

cin >> s;

c)

print(s);

d)

printf(s);

8.

Which command checks whether x equals 5?

a)

if(x == 5)

b)

if(x = 5)

c)

if(x === 5)

d)

if x = 5

9.

Which statement executes a block of code at least once and repeats while the condition is true?

a)

do-while

b)

for

c)

while

d)

repeat

10.

Which command adds the values a and b and stores the result in c?

a)

c = a + b;

b)

c = a - b;

c)

c = a * b;

d)

c = a / b;

11.

Which command increases the value of x by 5?

a)

x = x + 5;

b)

x = x - 5;

c)

x * 5;

d)

x / 5;

12.

Which command correctly prints the number stored in variable x?

a)

cout << x;

b)

cin >> x;

c)

print(x);

d)

printf(x);

13.

Which command inputs a number from the keyboard into the variable x?

a)

cin >> x;

b)

cout >> x;

c)

input(x);

d)

scanf(x);

14.

Which command prints the value of x inside a loop?

a)

cout << x;

b)

cin >> x;

c)

print(x);

d)

printf(x);

15.

Which operator adds two values a and b?

a)

-

b)

*

c)

+

d)

/

16.

Which command checks whether x is greater than 0?

a)

if(x > 0)

b)

if(x < 0)

c)

if(x == 0)

d)

if(x >= 0)

17.

Which loop runs while the condition is true?

a)

for

b)

while

c)

do-while

d)

repeat

18.

How do you assign the value 10 to variable x?

a)

x = 10;

b)

x := 10;

c)

x <= 10;

d)

x == 10;

19.

Which command prints "Welcome" if x is greater than 5?

a)

if(x > 5) cout << "Welcome";

b)

if(x > 5) cin >> "Welcome";

c)

if(x > 5) print("Welcome");

d)

if(x > 5) echo "Welcome";

20.

Which command prints "Even" if the number x is even?

a)

if(x % 2 == 0) cout << "Even";

b)

if(x % 2 = 0) cout << "Even";

c)

if(x / 2 == 0) cout << "Even";

d)

if(x * 2 == 0) cout << "Even";

21.

Which loop prints the numbers from 1 to 5?

a)

for(int i=1; i<=5; i++) cout << i;

b)

for(int i=0; i<5; i++) cout << i;

c)

while(i<=5) cout << i;

d)

do cout << i; while(i<=5);

22.

Which data type uses logical values (true/false)?

a)

int

b)

float

c)

bool

d)

char

23.

Which command decreases the value of x by 1?

a)

x++

b)

x--

c)

x = x + 1

d)

x = x * 1

24.

Which command checks whether x is less than or equal to 10?

a)

if(x <= 10)

b)

if(x < 10)

c)

if(x == 10)

d)

if(x => 10)

25.

Which operator subtracts the values a and b?

a)

+

b)

-

c)

*

d)

/

26.

Which statement repeats a block of code exactly 10 times?

a)

for(int i=0; i<10; i++)

b)

while(i<10)

c)

do-while

d)

repeat 10

27.

Which command checks whether x is NOT equal to 5?

a)

if(x != 5)

b)

if(x =! 5)

c)

if(x < 5)

d)

if(x != 5;)

28.

Which command prints a value n times?

a)

a) for(int i=0;i<n;i++) cout << n;

b)

if(n>0) cout << n;

c)

while(n) cin >> n;

d)

do cout << n; while(n);

29.

Which command checks whether x is greater than 0 and less than 10?

a)

if(x > 0 && x < 10)

b)

if(x > 0 || x < 10)

c)

if(x > 0 & x < 10)

d)

if(x >= 0 && x <= 10)

30.

Which command checks whether x is greater than 5 or y equals 10?

a)

if(x > 5 && y == 10)

b)

if(x > 5 || y == 10)

c)

if(x > 5 | y == 10)

d)

if(x > 5 and y == 10)

31.

Which input command uses multiple values at once?

a)

cin >> a >> b;

b)

cin << a << b;

c)

cin(a, b);

d)

input(a, b);

32.

Which operator returns the remainder in division?

a)

/

b)

%

c)

*

d)

//

33.

Which command prints the values from 1 to 10 using a while loop?

a)

int i = 1; while(i <= 10){ cout << i; i++; }

b)

for(i = 1; i <= 10; i++) cout << i;

c)

do cout << i; while(i <= 10);

d)

while(i < 10) cout << i;

34.

Which command checks whether x is greater than 0 and less than 5 or y equals 10?

a)

if((x > 0 && x < 5) || y == 10)

b)

if(x > 0 && x < 5 || y == 10)

c)

if(x > 0 & x < 5 | y == 10)

d)

if(x > 0 || x < 5 && y == 10)

35.

Which command decreases the value of x by 5?

a)

x = x - 5;

b)

x = x + 5;

c)

x--5;

d)

x = 1;

36.

Which command checks if the number x is even and greater than 0?

a)

if(x % 2 == 0 && x > 0)

b)

if(x % 2 = 0 && x > 0)

c)

if(x % 2 == 0 || x > 0)

d)

if(x / 2 == 0 && x > 0)

37.

Which output command uses a new line after the text?

a)

cout << "Hello" << endl;

b)

cout >> "Hello" << endl;

c)

cout << "Hello";

d)

cout << Hello;

38.

Which command checks if x is greater than 10 and less than 20?

a)

if(x > 10 && x < 20)

b)

if(x > 10 || x < 20)

c)

if(x > 10 && x <= 20)

d)

if(x = 10 && x = 20)

39.

Which operator multiplies two values a and b?

a)

+

b)

-

c)

*

d)

/

40.

Which command assigns the value 100 to the variable y?

a)

y == 100;

b)

y = 100;

c)

y := 100;

d)

y <= 100;