EXPRESSION AND ASIGNMENT STATEMENTS

EXPRESSION AND ASIGNMENT STATEMENTS

Expressions are fundamental means of specifying computation in programming language. We need to be familiar with orders of operator and operand evaluation to understand expression evaluation. This is very important for programmer to understand syntax, semantics, and expression from the used programming language.

Arithmetic expressions , consist of operators, operands, parentheses, and function call.

  • Operators

Unary operator: has one operand

Binary operator: has two operands

Ternary operator: has three operands

Operator precedence rules: parentheses → unary operators → **(if the language support) → *, / → +,- .

Operator associativity rule: rules for expression evaluation define the order when the operators precedence level are same. Typical associativity rules is left to right, except **. And sometimes unary operators associate right to left.

Overloaded operators is when an operator used for more than one purpose. For example: + for int and float. C++, C#, and F# allow user-defined overloaded operators.  But there are potential problems: user can define nonsense operations, and readability may suffer even when the operators make sense.

Type conversions :

Narrowing conversion, convert an object to a type that cannot include all of the values  of the original type. Example: float to int.

Widening conversion, object converted to a typep that can include at elase approximations to all of the values of the original type. Example: int to float.

An error can occur in expression because division by zero, limitation of computer arithmetic.

Relational and Boolean expressions

  • Relational expression: use relational operators and operands of various tupes, evaluate to some Boolean representation
  • JS and PHP have two additional operator, === and !==, it’s similar to == and != except they do not coerce their operands. Coercion is an implicit type conversion, in most  language all numeric types are coerced in expression using widening conversions.

Short-circuit evaluation is an expression which the result is determined without evaluating all of the operands and/or operators. Example: (13 * a) * (b / 13 -1 ). If a is zero, there is no need to evaluate (b / 13 -1 ).

Assignment statements is a process to save a value in some location that named as variable.

Mixed mode assignment, in Fortran, C, Perl, and C++ any numeric type value can be assigned to any numeric type variable. In java and C# only widening assignment coercions are done. In Ada there is n assignment coercion.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *