Зміст курсу
Вступ до C++
Вступ до C++
Прості оператори
Оператор присвоєння (=)
використовується в програмуванні для присвоєння значення змінній. Синтаксис виглядає наступним чином:
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 how the outputs appear on the same line 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 achive something.
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.
Дякуємо за ваш відгук!