Problem Solving using C Language

0 of 77 lessons complete (0%)
Back to lesson

Quiz: Conditional Statement Quiz

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

    1

    int a = 10;
    if (a > 5)
    {
    printf(“Greatern”);
    }
    printf(“Endn”);

  2. 2. What happens if there is no break statement in a switch case?

    1
  3. 3. Which of the following is not true about the else statement?

    1
  4. 4. In a nested if-else structure, how does the compiler determine which else matches which if?

    1
  5. 5. What is the output of the following switch statement?

    1

    int day = 2;
    switch (day) {
    case 1: printf(“Sundayn”); break;
    case 2: printf(“Mondayn”); break;
    case 3: printf(“Tuesdayn”); break;
    default: printf(“Invalid dayn”);
    }

  6. 6. What will the following code print if x = 6?

    1

    if (x > 0)
    if (x % 2 == 0)
    printf(“Evenn”);
    else
    printf(“Oddn”);
    else
    printf(“Negativen”);

  7. 7. What does the following code output if x = 5?

    1

    if (x == 5)
    printf(“x is 5n”);
    else
    printf(“x is not 5n”);

  8. 8. What will the following code output?

    1

    int a = 3;
    if (a > 0)
    {
    if (a < 10)
    {
    printf(“An”);
    }
    else
    {
    printf(“Bn”);
    }
    }

  9. 9. What will the following code output?

    1

    int x = 4;
    if (x == 5)
    printf(“x is 5n”);
    else if (x == 4)
    printf(“x is 4n”);
    else
    printf(“x is unknownn”);

  10. 10. What is the output of the following code?

    1

    int num = 10;
    if (num > 10)
    printf(“Greater than 10n”);
    else if (num == 10)
    printf(“Equal to 10n”);
    else
    printf(“Less than 10n”);