operator in c++ || AsgarTech

 


operator in c++


An operator in C++ is a symbol that tells the compiler to perform a specific mathematical or logical manipulation. C++ has a rich set of built-in operators, which can be classified into the following categories


Arithmetic operators: These operators are used to perform arithmetic operations on numbers. For example, the + operator is used for addition, the - operator is used for subtraction, the * operator is used for multiplication, and the / operator is used for division.


Relational operators: These operators are used to compare two values. For example, the == operator is used to check if two values are equal, the != operator is used to check if two values are not equal, the > operator is used to check if a value is greater than another value, and the < operator is used to check if a value is less than another value.


Logical operators: These operators are used to combine two or more logical expressions. For example, the && operator is used to perform a logical AND operation, the || operator is used to perform a logical OR operation, and the ! operator is used to perform a logical NOT operation.


Bitwise operators: These operators are used to manipulate the bits of a value. For example, the & operator is used to perform a bitwise AND operation, the | operator is used to perform a bitwise OR operation, the ^ operator is used to perform a bitwise XOR operation, and the ~ operator is used to perform a bitwise NOT operation.


Assignment operators: These operators are used to assign a value to a variable. For example, the = operator is used to assign a value to a variable, the += operator is used to add a value to a variable, the -= operator is used to subtract a value from a variable, and the *= operator is used to multiply a value by a variable.



Conditional operator Ternary ?: Evaluate two expressions and return the result of the first expression if the condition is true, or the result of the second expression if the condition is false.


sizeof operator Size of sizeof Returns the size of a variable or type.
Scope resolution operator

Scope resolution :: Used to access members of a class or namespace from outside of that class or namespace.


Member access operator Member access . Used to access members of an object.


Pointer to member operator Pointer to member -> Used to access members of an object through a pointer to that object.


Cast operator Cast (type) Used to cast a value to a different type.


New operator Memory allocation new Allocates memory on the heap.
Delete operator Memory deallocation delete Deallocates memory on the heap

Operator Category Syntax Description

Arithmetic operators Arithmetic +, -, *, /, %, ++, -- Perform arithmetic operations on numbers.


Relational operators Relational ==, !=, <, >, <=, >= Compare two values.


Logical operators Logical &&, ` ,!`


Bitwise operators Bitwise &, ` ,^,~,<<,>>`

Assignment operators Assignment =, +=, -=, *=, /=, %=, &=, ` =,^=,<<=,>>=
Increment and decrement operators Increment and decrement ++, -- Increment or decrement the value of a variable by 1.
thanks


No comments: