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

26.What is the output of the following program ?

#include <iostream>
using namespace std;

int main() 
{
    int var = 0;
    while (var < 10) 
    {
        cout << var << " ";
        var++;
    }
    cout << var;
    return 0;
}

Solution

Output:
0 1 2 3 4 5 6 7 8 9 10

Explanation:

  • The variable var starts at 0.

  • The while (var < 10) loop prints 0 1 2 3 4 5 6 7 8 9 with spaces.

  • When var reaches 10, the loop stops.

  • After the loop, cout << var; prints 10.

    Final output:

    0 1 2 3 4 5 6 7 8 9 10

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...