Ask Question
19 April, 18:07

What is the output of the following C+ + code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; c

+3
Answers (1)
  1. 19 April, 19:19
    0
    Complete Question:

    What is the output of the following C+ + code?

    int x = 55;

    int y = 5;

    switch (x % 7)

    {

    case 0:

    case 1:

    y++;

    case 2:

    case 3:

    y = y + 2;

    case 4:

    break;

    case 5:

    case 6:

    y = y - 3;

    }

    cout << y << endl;

    A. 2

    B. 5

    C. 8

    D. 10

    Answer:

    A) 2

    Explanation:

    In this code snippet provided which shows the use of the switch statement in C++. Two variables have been declared and initialized.

    int x=55 and int y = 5;

    The condition of the switch statement (x%7) evaluates to 6. Therefore case 6: gets executed which is y-3 and this is equal to 2 since the initial value of y was 5. The output statement cout << y << endl; prints 2 to the console
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is the output of the following C+ + code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers