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
- Read the program carefully.
- Predict the output without running the code.
- Write your predicted output.
- Run the program to verify your answer.
- Understand why the output appears.
- 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;
}