Expressions and Assignment Statements
Assignment from Tri Djoko Wahjono
1. Define operator precedence and operator associativity.
Operator precedence is a rule used to clarify which procedures should be performed first in a given mathematical expression.
Operator associativity is a property that determines how operators of the same precedence are grouped in the absence of parentheses
2. What is a ternary operator ?
An operator that takes three operands
3. What is a prefix operator ?
An operator which signifies function of one argument which argument immediately follows an occurrence of the operator
4. What operator usually has right associativity ?
The “*” (pointer) operator
5. What is a nonassociative operator ?
An operator that have no defined behavior when used in sequence in an expression
8. Define functional side effect
A condition where a function changes either one of its parameters or a global variable.
9. What is a coercion ?
A method of automatically converting one type of data to another.
10. What is a conditional expression ?
A compound of expression that contains a condition and some constrains
11. What is an overloaded operator ?
Operator that has different implementation depending on its arguments.
12. Define narrowing and widening conversion
Widening conversion is a conversion that converts a value to a type that can include least approximations of all values of the original type. Narrowing conversion is a conversion of data that might cause a loss of precision.
1. When might you want the compiler to ignore type differences in an expression ?
When I want naming a variable as a string.
2. State your own arguments for and against allowing mixed-mode arithmetic expressions.
A mixed mode arithmetic expression is needed in calculating expressions that might have decimal results. It is compulsory as it allows two different type of number data type such as float and integer to be summed without losing the precision of the float.
While it is compulsory to have mixed-mode expressions, it is more error prone when expressions made are more likely to have non-decimal results. A mixed mode might produce a decimal result even though the result wanted is a non-decimal.
3. Do you think the elimination of overloaded operators in your favorite language would be beneficial ? why or why not ?
No, it would not be beneficial. Overloading operator would be a helpful feature in developing a complex program with complex arithmetic operation as well. It allows developers to create a class whose function can replace countless lines of codes with an operator. This clearly will help a readability and writability of a program. Eliminating overloaded operators would null this advantage.
4. Would it be a good idea to eliminate all operator precedence rules and require parentheses to show the desired precedence in expressions ? Why and why not ?
No , it would not be a good idea. Although this custom precedence sounds like increasing flexibility, requiring parentheses to show a custom precedence would impact in readability and writability of a program.
5. Should C’s assigning operations (for example, +=) be included in other languages (that do not already have them) ? Why or why not ?
No. C’s assigning operations should not be included in other languages. Because this assigning operations would be the different part of the code if it is implemented on other code that might cause confusion of the programmer or even it might disrupt the semantics of a language’s syntax.