expression, operators, and operands in programming:
Expression :
In programming languages, an expression is a combination of operands (variables and constants ) and operators. There may be more than one operands and operators in an expression. The expression can be written in many ways but it can’t be without an operator or operand. Operator and operands are an essential part to create an expression.
For example
1. Operand1 (operator) operand2
x + y => here x and y are operands and ‘+’ is an operator
2. Operator (operand)
-x => here ‘-’ is an operator and x is an operand
An expression may contain many operands and many operators. There are three types of expressions
- Arithmetic expressions
- Relational expressions
- Logical expressions
Operands :
The value on which we want to perform a specific operation is called an operand. Variables can behave as operands.
Operators :
An operator is a symbol or sign that is used to perform a specific task on data. Unary operator requires single operand and binary operator requires two operands. Following are the types of operators in programming :
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Increment and Decrement operators
- Assignment operator
Arithmetic Expressions and Arithmetic operators
Arithmetic expressions contain arithmetic operators, constants, and variables. ( +, -, *, /, % ) are arithmetic operators. These operators are used for all types of numeric data except the remainder (%) operator. These operators evaluated from left to right. The compiler performs only one arithmetic operation at a time. Arithmetic operators are of two types.
Unary operator
Binary operator
The precedence of the unary operator is higher than the binary operator. Similarly, the precedence of multiplication and division is higher than the precedence of addition and subtraction.
However, precedence of division and multiplication are equal and precedence of addition and subtraction are equal.
Relational Expressions and Relational operators
A combination of relational operators with constants and variables form relational expressions. All relational operators are binary operators. Relational operators also called comparing operators. There are 6 relational operators ( <, >, <=, >=, ==, != ). They always evaluate to true or false. True is represented by 1 and false is represented by 0. Relational expressions also evaluate from left to right. These operators have no precedence over each other.
Operator | Meaning | Expression |
---|---|---|
< | less than | a |
> | greater than | a>b |
<= | less than or equal to | a<=b |
>= | greater than or equal to | a>=b |
"==" | equal to | a==b |
!= | not equal to | a!=b |
Logical Expressions and Logical Operators
Logical operators are used to combining two or more relational expressions. i.e, relational expressions with logical operators form a logical expression. There are three logical operators.
And ( && )
Or ( || )
Not ( ! )
&& and || are binary operators and Not (!) is a unary operator. These operators also produce true or false results. Not operator has the highest precedence. If more than one logical operator is involved in an expression then the expression will be evaluated from left to right.
to learn more subscribe to our channel and click here
Pingback: Increment and decrement operator in c programming | C++
Thank you for sharing your thoughts. I truly appreciate your efforts and I will be waiting for your further post thanks once again.
It’s going to be end of mine day, however before end I am
reading this enormous piece of writing to improve
my experience.