Course Content
C++ Introduction
C++ Introduction
Operators Introduction
Operators are symbols or keywords in programming that perform operations on variables or values. They are the building blocks for performing tasks like arithmetic, comparisons, logical decisions, and more.
+ , - , * , / , % | == , != , < , > , <= , >= | && , || , & , | | ++ , -- |
Arithmetic operators are the most basic ones; they include well-known signs like addition (+
), multiplication (*
), subtraction (-
), division (/
), and modulo (%
) for calculating the remainder of a division.
main
#include <iostream> int main() { // `std::endl` moves each `std::cout` output to a new line // You can try removing `std::endl` to see the result std::cout << 5 + 5 << std::endl; std::cout << 5 - 5 << std::endl; std::cout << 5 / 5 << std::endl; std::cout << 5 * 5 << std::endl; std::cout << 5 % 5 << std::endl; }
Each operator has its unique function, and all of them can be divided into categories: unary, binary, and ternary. Arithmetic operators are binary because they require two operands to achieve a result.
main
#include <iostream> int main() { // 5 (first operand) // - (operation) // 3 (second operand) std::cout << 5 - 3 << std::endl; }
Removing an operand from an operator that requires it will result in an error, as the program expects the correct number of operands to perform the operation.
Unary operators, such as decrement and increment, require only one operand, while ternary operators need three. We will explore each category of operators from the beginning, learning how they work and what they require.
Thanks for your feedback!