C++ Basics Quiz

C++ Basics Quiz

University

25 Qs

quiz-placeholder

Similar activities

TEMA 17 Examen de Salesforce

TEMA 17 Examen de Salesforce

University

20 Qs

Лекция 5. Циклы в Java

Лекция 5. Циклы в Java

University

20 Qs

Revision Quiz 3

Revision Quiz 3

9th Grade - University

30 Qs

Quiz-1-Set-1-OOPs-CPP

Quiz-1-Set-1-OOPs-CPP

University

20 Qs

Pretest Alpro Dasar

Pretest Alpro Dasar

University

20 Qs

Pemrograman Blokly

Pemrograman Blokly

9th Grade - University

20 Qs

Introdução a Programação Estruturada em C

Introdução a Programação Estruturada em C

University

26 Qs

SAS Dasar Program Keahlian RPL Kelas X

SAS Dasar Program Keahlian RPL Kelas X

10th Grade - University

25 Qs

C++ Basics Quiz

C++ Basics Quiz

Assessment

Quiz

Information Technology (IT)

University

Hard

Created by

Maria Macuha

Used 2+ times

FREE Resource

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.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?