Learn with Yasir

Share Your Feedback

C++ Basics: Output Practice Questions


Practice basic C++ output concepts with simple exercises on cout, variables, arithmetic expressions, and predicting console output for beginner programmers.

Instructions for Students

  1. Read the program carefully.
  2. Predict the output without running the code.
  3. Write your predicted output.
  4. Run the program to verify your answer.
  5. Understand why the output appears.
  6. Modify the code and predict the new output.

Question 1: Displaying Variable Values

Task: Predict the output.

Code

int x = 10;
int y = 5;
cout << x - y;

Question 1: Displaying Variable Values

Task: Predict the output.

Code

#include <iostream>
using namespace std;

int main()
{
    int a = 10;
    int b = 20;

    cout << a << endl;
    cout << b << endl;

    return 0;
}

Question 3: Arithmetic Calculations

Task: Predict the output of each calculation.

Code

#include <iostream>
using namespace std;

int main()
{
    int a = 10;
    int b = 3;

    cout << a + b << endl;
    cout << a - b << endl;
    cout << a * b << endl;
    cout << a / b << endl;
    cout << a % b << endl;

    return 0;
}

Question 4: Combining Variables and Operators

Task: Trace the code and predict the output.

Code

#include <iostream>
using namespace std;

int main()
{
    int x = 5;
    int y = 2;

    x = x + 3;
    y = y * 2;

    cout << x << endl;
    cout << y << endl;
    cout << x + y << endl;

    return 0;
}