#include<bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
// Declare variables
int a = 5;
int b = 10;
int sum;
// Add 'a' and 'b' and store the result in 'sum'
sum = a + b;
// Output the result
cout << "The sum of a and b is: " << sum << endl;
return 0;
}
Explanation:
- #include <bits/stdc++.h>
: Includes a library that contains commonly used libraries in competitive programming and isn't part of the standard C++ libraries.
- using namespace std;
: Allows using elements from the standard C++ library without specifying the namespace.
- int main() { ... }
: Entry point of the program. Execution begins from here.
- int a = 5;
and int b = 10;
: Declaration and initialization of integer variables 'a' and 'b'.
- int sum;
: Declaration of an integer variable 'sum'.
- sum = a + b;
: Adds the values of 'a' and 'b' and stores the result in the 'sum' variable.
- cout << "The sum of a and b is: " << sum << endl;
: Outputs the sum of 'a' and 'b' to the console.
- return 0;
: Indicates successful termination of the program.