Professional Documents
Culture Documents
Programming Fundamentals 04
Programming Fundamentals 04
PROGRAMMING
LECTURE #04
ARITHEMETIC OPERATORS
C++ COMMENTS
• Comments can be used to explain C++ code, and to make it more readable. It can also be
used to prevent execution when testing alternative code. Comments can be singled-lined
or multi-lined.
SINGLE-LINE COMMENTS
• Any text between // and the end of the line is ignored by the compiler (will not be
executed).
• In the example below, we use the + operator to add together two values:
#include <iostream>
int main() {
int x = 5;
int y = 3;
cout << x + y;
return 0;
Output:
8
MINUS – OPERATOR
#include <iostream>
int main() {
int x = 5;
int y = 3;
cout << x - y;
return 0;
Output:
2
MULTIPLY * OPERATOR
#include <iostream>
int main() {
int x = 5;
int y = 3;
cout << x * y;
return 0;
Output:
15
DIVIDE / OPERATOR
#include <iostream>
using namespace std;
int main() {
int x = 12;
int y = 3;
cout << x / y;
return 0;
}
Output:
4
MODULUS % OPERATOR
#include <iostream>
using namespace std;
int main() {
int x = 5;
int y = 2;
cout << x % y;
return 0;
}
Output:
1