Aspire Faculty ID #12787 · Topic: JECA MCA 2023 · Just now
JECA MCA 2023

32.What is the output of the following program ?
#include <iostream>
using namespace std;

int main()
{
    int var = 2;
    do
    {
        cout << var;
    } while (var--);
    return 0;
}

Solution

  • Explanation:

    • Initially var = 2.

    • First iteration: prints 2, then var-- makes var = 1.

    • Second iteration: prints 1, then var-- makes var = 0.

    • Third iteration: prints 0, then var-- makes var = -1. Condition fails and loop exits.

    So output is:

Previous 10 Questions — JECA MCA 2023

Nearest first

Next 10 Questions — JECA MCA 2023

Ascending by ID
Ask Your Question or Put Your Review.

loading...