Monday, October 29, 2018

Operator, Operand, and Arithmetic

What are Operator and Operand?

An operator is a symbol to process the values in the result of a new value

An operand is a part that specifies which data should be manipulated or exploited



Example

X = Y + Z  

= and + sign are operators
X, Y and Z are operands

Depending on its type of operation, the operator can be grouped as follows:
Assignment Operator
Used to assign a value to an operand
Syntax:
Operand1 = Operand2;
The left operand (Operand1) must have a value, such as variable
The operand on the right (Operand2) can be a constant, another variable, an expression or
a function.
Example
x=5;
Arithmetic Operator


Example of increment and decrement:
Increment x=1, x++ >>>>x=2
Decrement x=1,x--    >>>>x=0

Relational operator
Used to compare values with True or False
-->
Symbol
Functionality
==
Equality
!=
Not equal
<
Less than
>
Greater than
<=
Less or equal than
>=
Greater or equal than
?:
Conditional assignment
False in C has a value of zero(0)
True in C has a value of one(1)

Conditional Expressions:
if(a > b)  z = a;
else z = b;
can be written as:     z = (a > b) ? a : b;
Logical Operator
Operand in Logical Operator is the operand with the value TRUE or FALSE.









Bitwise operator
-->
Symbol
Meaning
Example
&
AND
A & B
|
OR
A | B;
^
XOR
A ^ B;
~
Complement
~A;
>>
Shift Right
A >> 3;
<<
Shift Left
B << 2;
--> int A=24; int B=35; int C;Example:
C = A & B;  // value C = 0
C = A | B;    // value C = 59
Note:
A=24 binary: 011000
B=35 binary: 100011
Bit by bit AND operation resulting: 000000, in decimal: 0
Bit by bit OR operation resulting : 111011, in decimal: 59
Pointer Operator
Pointer is an operator that uses the symbols "&" and "*" to search the data
addresses and data values of a variable whose uses are:
& = address
* = value of


By :Steven
2201852132
Computer Science and Statistics



No comments:

Post a Comment