Aspire's Library

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

Previous Year Question (PYQs)



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:



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