Search Header Logo

C++ Basics Quiz

Authored by Maria Macuha

Information Technology (IT)

University

Used 2+ times

C++ Basics Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

25 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

Which operator checks if two values are equal?

=

==

!=

<=

2.

MULTIPLE CHOICE QUESTION

20 sec • 2 pts

What will be printed? int x = 10, y = 20; if (x < y) cout << "Yes"; else cout << "No";

Yes

No

Error

Nothing

Answer explanation

The condition 'x < y' evaluates to true since 10 is less than 20. Therefore, the program executes the first branch of the if statement, printing 'Yes'.

3.

MULTIPLE CHOICE QUESTION

20 sec • 2 pts

Which statement correctly checks if n is negative?

if (n = 0)

if (n < 0)

if (n <= 0)

if (n == 0)

Answer explanation

The correct statement to check if n is negative is 'if (n < 0)'. This condition evaluates to true when n is less than zero, accurately identifying negative numbers. The other options do not correctly check for negativity.

4.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

Which keyword is used when the if condition is false?

elseif

switch

else

continue

Answer explanation

The keyword 'else' is used to define a block of code that executes when the 'if' condition is false. It provides an alternative path in conditional statements.

5.

MULTIPLE CHOICE QUESTION

20 sec • 2 pts

What is the output if the user enters -5? int value; cin >> value; if (value < 0) value = -value; cout << value;

-5

5

0

Error

Answer explanation

When the user enters -5, the condition 'value < 0' is true, so 'value' is set to -(-5), which is 5. Therefore, the output is 5.

6.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What is the logical AND operator in C++?

||

&&

!

&

Answer explanation

The logical AND operator in C++ is represented by '&&'. It evaluates to true only if both operands are true. The other options represent different operations: '||' is OR, '!' is NOT, and '&' is bitwise AND.

7.

MULTIPLE CHOICE QUESTION

20 sec • 2 pts

Which code correctly checks if a number is even?

if (n/2)

if (n % 2 == 0)

if (n % 2)

if (n == 2)

Answer explanation

The correct choice is 'if (n % 2 == 0)', which checks if the remainder of n divided by 2 is zero, indicating that n is even. The other options do not correctly determine if a number is even.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?