Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



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



Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...