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

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

void print();
int main()
{
    int var = 0;
    var = print();
    cout << var;
    return 0;
}

void print()
{
    cout << "Hi";
}

Solution

  • Explanation:

    • print() is declared as void print().

    • In main(), the statement var = print(); tries to assign the return value of print() to an int variable.

    • But since print() has no return value (void), this causes a compile-time error.

    Hence, the program does not compile.

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