Showing posts with label datatypes. Show all posts
Showing posts with label datatypes. Show all posts

Friday, February 16, 2024

C++ DATATYPES/OPERATORS/VARIABLES

C++ datatypes/operators/variables


  • DIFFERENT TYPES OF OPERATORS

Operators

Operators are different types of functions that take one or more arguments and create a new value. For example: addition (+), subtraction (-), multiplication(*), etc. are all operators. Operators are used to perform various operations on variables and constants.

Types of operators

·       Assignment operator

·       Mathematical operator

·       Relational operator

·       Logical operator

·       Bitwise operator

·       Shift operator

·       Unary operator

·       Ternary operator

·       Comma operator

 

Assignment Operator(=)

The function '=' is used as an assignment, it takes the right side (called rvalue) and copies it to the left side (called lvalue). The assignment operator is the only operator that can be overloaded but not inherited.

Mathematical Operations

There are operators used to perform basic mathematical operations. Addition (+), subtraction (-), deviation (/), multiplication (*), and modulus (%) are basic mathematical operators. The modulus operator cannot be used with floating point numbers.

Relationship Operators

These operators create a relationship between operators. The relational operators are: less than (andlt;), latch than (andgt;), less than or equal to (andlt;=), greater than equal to (andgt;=), equal to (==), and not equal to (! =). Note that the assignment operator is (=) and there is a relational operator for the corresponding (==). The two differ, the assignment operator assigns a value to some variable, while the equality operator is used to compare values, as in if-else conditions.

Logical operators

The logical operators are AND (and) and OR (||). They are used to connect two different expressions. If two commands are combined with the AND operator, both commands are considered valid, but if they are combined with the OR operator, one of them must be valid. These operators are mostly used in loops (especially while loop) and decision-making.

Bitwise operators

These are used to convert individual bits to numbers. They only work with integral data types such as char, int, and long, not floating-point numbers.

·       bitwise AND operators

·       bitwise OR operators

·       bitwise operator XOR ^

·       bitwise NOT operator ~

They can also be used as abbreviations =, |=, ^=, ~=, etc.

Shift operators

Shift operators are used to change bits of some variable. There are three types:

·       Left shift operator <<

·       Right shift operator >>

·       Unsigned right shift operator >>>

Unary operators

These are operators that operate on only one operand. There are many unary operators, but the most commonly used ones are the increment ++ and decrement.

Other unary operations: address and, reference *, new and delete, bit-bit-not ~, logical not !, unary minus - and unary plus +.

Ternary operator

Ternary if-else? : is an operator with three operands.

The comma operator

It is used to separate variable names and expressions. For expressions, the value of the last expression is produced and used.

Featured Post

ASSOCIATION RULE IN MACHINE LEARNING/PYTHON/ARTIFICIAL INTELLIGENCE

Association rule   Rule Evaluation Metrics Applications of Association Rule Learning Advantages of Association Rule Mining Disadvantages of ...

Popular