Welcome to our comprehensive guide on C++ Operators! This tutorial is designed for both beginners and intermediates, covering a wide range of topics in an easy-to-understand manner.
Arithmetic Operators
+)-)*)/)%)++)--)Relational Operators
==)!=)>)<)>=)<=)Logical Operators
&&)||)!)Assignment Operators
=)+=)-=)*=)/=)%=)Bitwise Operators
&)|)^)~)<<)>>)Miscellaneous Operators
&)*)Which operator is used for the increment of a variable?
Arithmetic operators are used to perform mathematical operations. Let's explore each one.
+)Adds two operands.
int a = 5;
int b = 3;
int sum = a + b; // sum = 8-)Subtracts one operand from another.
int a = 10;
int b = 3;
int difference = a - b; // difference = 7*)Multiplies two operands.
int a = 5;
int b = 3;
int product = a * b; // product = 15/)Divides one operand by another.
int a = 10;
int b = 3;
float quotient = (float)a / b; // quotient = 3.33333%)Calculates the remainder of a division operation.
int a = 10;
int b = 3;
int remainder = a % b; // remainder = 1++) and Decrement (--) OperatorsIncrement increases the value of a variable by 1. Decrement decreases the value of a variable by 1.
int a = 5;
a++; // a = 6
int b = 5;
--b; // b = 4Remember, there's more to learn about these operators and other topics in C++! Stay tuned for our next lessons. ā
Note: Always make sure to declare variables before using them in your code. This ensures there are no runtime errors.
Pro Tip: Use operators wisely to write clean, efficient, and easy-to-read code.