Components of C++
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built‐in operators and provides following type of operators:
Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Misc Operators
This chapter will examine the arithmetic, relational, and logical, bitwise, assignment and other operators one by one.
There are following arithmetic operators supported by C++ language: Assume variable A holds 10 and variable B holds 20 then: Operator + ‐ * / % ++ ‐‐ Adds two operands Subtracts second operand from the first Multiply both operands Divide numerator by de‐numerator Modulus Operator and remainder of after an integer division Increment operator, increases integer value by one Decrement operator, decreases integer value by one Description Example A + B will give 30 A ‐ B will give ‐10 A * B will give 200 B / A will give 2 B % A will give 0 A++ will give 11 A‐‐ will give 9
There are following relational operators supported by C++ language Assume variable A holds 10 and variable B holds 20 then: Operator == != > = B) is not true. (A = B) is not true. (A (arrow) Cast & * Description sizeof operator returns the size of a variable. For example sizeof(a), where a is integer, will return 4. Conditional operator. If Condition is true ? then it returns value X : otherwise value Y Comma operator causes a sequence of operations to be performed. The value of the entire comma expression is the value of the last expression of the comma‐separated list. Member operators are used to reference individual members of classes, structures, and unions. Casting operators convert one data type to another. For example, int(2.2000) would return 2. ...
Please join StudyMode to read the full document