Search Header Logo

Decision making in C

Authored by Dr. Singh

Computers

University

Used 6+ times

Decision making in C
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

  1. What is the correct syntax for an if statement in C?

if condition { /* code to execute */ }
if (condition) /* code to execute */
if { condition } { /* code to execute */ }
if (condition) { /* code to execute */ }

2.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

  1. Which of the following statements is true about the else if construct?

The 'else if' construct can only be used once in a program.
The 'else if' construct does not allow for nested conditions.
The 'else if' construct is only applicable in switch statements.
The 'else if' construct allows for multiple conditional checks.

3.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

  1. What will the following code print if x = 10?

    if (x < 5) {

    printf("Less than 5");

} else if (x < 15) {

    printf("Less than 15");

} else {

    printf("15 or more");

}

Exactly 10
Less than 5
Less than 15
15 or more

4.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

  1. In C, which of the following statements correctly implements a switch-case?

switch(expression) { case value1: // code block; default: // code block; }

switch(value) { case value1: // code block; case value2: // code block; }
switch(expression) { case value1: // code block; break; case value2: // code block; break; default: // code block; }
switch(expression) { case value1: // code block; break; case value2: // code block; continue; }

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What will the following code output if num is 3?

switch (num) {

    case 1:

        printf("One");

        break;

    case 2:

        printf("Two");

        break;

    default:

        printf("Default");

        break;

}

One
Three
Two
Default

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. Which of the following expressions is evaluated in an if statement in C?

Integer values only

Boolean values only

Any expression that evaluates to zero (false) or non-zero (true)

String literals only

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What is the output of the following code segment?

int a = 5, b = 10;

if (a > b)

    printf("A is greater");

else if (a < b)

    printf("B is greater");

else

    printf("A and B are equal");

A and B are equal
B is greater
A is greater
B is less than A

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?