Here is an example of how to add two variables in C++:
#include <iostream>
int main() {
int x = 5;
int y = 7;
int sum = x + y;
std::cout << "The sum of x and y is: " << sum << std::endl;
return 0;
}
This code defines two variables x
and y
and assigns them the values 5 and 7, respectively. It then calculates the sum of x
and y
and stores the result in a third variable sum
. Finally, it prints the value of sum
to the console using the cout
stream from the iostream
library.
Leave a Reply