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:--
    • OperatorsOperationsExample
      ^ExponentialA^B
      -Negation-B
      *MultiplicationA*B
      /Floating point divisionA/B
      \integer divisionA\B
      MODModular DivisionA MOD B
      +AdditionA+B
      -SubtractionA-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:-
    • OperatorsNamesExample
      =EqualA=B
      <Less thanA<B
      >Greater thanA>B
      <=Greater than equal toA<=B
      >=less than equal toA>=B
      <>Not equal toA <> 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:-
    • OperatorsNamesExample
      ANDConjunctionA<B AND A<C
      ORDis-junctionA<B OR A<C
      NOTNegativeA<>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:-:--
    • OperatorsNamesExample
      ANDConjunctionA<B AND A<B
      ORDis-junctionA<B OR A<B
      NOTNegativeA<>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:-

Comments

Post a Comment

Popular posts from this blog

Features of QBASIC