Practice basic C++ output concepts with simple exercises on cout, variables, arithmetic expressions, and predicting console output for beginner programmers.
Task: Predict the output.
int x = 10;
int y = 5;
cout << x - y;
Task: Predict the output.
#include <iostream>
using namespace std;
int main()
{
int a = 10;
int b = 20;
cout << a << endl;
cout << b << endl;
return 0;
}
Task: Predict the output of each calculation.
#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;
}
Task: Trace the code and predict the output.
#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;
}