Expression Types and operators with Example
- Expression and Operator
- Expression is a programming language statements that has a value. Usually an expression consists of an operator and each operands.
Operator performs mathematical or logical operations on value QBASIC supports following types of operators.- Types of Operators:-
- a) Arithmetic operator
- b) Relational Operators
- c) Logical Operators
- d) String Operators
- a) Arithmatic Operators:-
- Arithmetic operator are used for various mathematical calculation . Arithmetic operators performed such as addition, subtraction, multiplication, division and exponentiation. A numeric expression is any collection of operators and operands.
- a) The following are the arithmetic operator used in QBASIC:--
Operators Operations Example ^ Exponential A^B - Negation -B * Multiplication A*B / Floating point division A/B \ integer division A\B MOD Modular Division A MOD B + Addition A+B - Subtraction A-B
- Example Code:-
- Example Output:-
- b) Relational Operators:-
- Relational Operator are used to compare two values of some type either both numeric or both string. A comparison of sting data with numeric data cannot be done. The comparison of string data is done on the basis of ASCII value. The result of comparison is either true (non zero) or false (zero).
- The relation operator supported by QBASIC are:-
Operators Names Example = Equal A=B < Less than A<B > Greater than A>B <= Greater than equal to A<=B >= less than equal to A>=B <> Not equal to A <> B
- c) Logical Operators:-
- Logical Operators combine two or more relational expressions to evaluate a single value as True (Non Zero) or False (Zero). The result of evaluation is used to make decisions about the program flow. The commonly used logical operators in QBASIC are AND, OR and NOT.
- The Logical operators supported by QBASIC are:-
Operators Names Example AND Conjunction A<B AND A<C OR Dis-junction A<B OR A<C NOT Negative A<>B
- c) Logical Operators:-
- Logical Operators combine two or more relational expressions to evaluate a single value as True (Non Zero) or False (Zero). The result of evaluation is used to make decisions about the program flow. The commonly used logical operators in QBASIC are AND, OR and NOT.
- The Logical operators supported by QBASIC are:-:--
Operators Names Example AND Conjunction A<B AND A<B OR Dis-junction A<B OR A<B NOT Negative A<>B
- Rules of Logical operators:-:-
- i) The output of the logical AND operation is TRUE if Both the logical expressions are individually TRUE.
- ii) The output of the logical OR operation is TRUE if either or the logical expressions is TRUE.
- iii) The logical NOT is negative check operator. The out put of the logical NOT operations is TRUE if the expressions being tested is FALSE
- d) String Operators:-
- The joining of two or more strings is called concatenation of string. The string are connected by the string operators which is the plus sign (+).
- Example Code:-
- Example Output:-
Completed all Question Answer :)
ReplyDeleteBikash
ReplyDelete