Chapter 7 Programming Languages

¡Supera tus tareas y exámenes ahora con Quizwiz!

What operator usually has right associativity?

** operator which can be found in fortran and ruby

What is coercion

A coercion is an implicit type conversion

What is referential transparency?

A program has the property of referential transparency if any two expressions in the program that have the same value can be substituted for one another anywhere in the program without affecting the action of the program.

What is short-circuit evaluation?

An expression in which the result is determined without evaluating all of the operands and/or operators.

Describe a situation in which the add operator in a programming language would not be commutative? a + b = b + a

An expression such as a + fun(b), as described on page 300.

How does C support relational and Boolean expressions?

By using numeric types to express the Boolean value 0 for false and 1 for true

What is the purpose of a compound assignment operator?

Compound assignment operator is a shorthand method of specifying a commonly needed form of assignment. The form of assignment that can be abbreviated with this technique has the destination variable also appearing as the first operand in the expression on the right side.

Describe a situation in which the add operator in a programming language would not be associative. a + (b + c) = (a + b) + c

Consider the integer expression A + B + C. Suppose the values of A,B, and C are 20,000, 25000, and -20000, respectively. Further suppose that the machine has a maximum integer value of 32767. If the first addition is computed first, it will result in overflow. If the second addition is done first, the whole expression can be correctly computed.

What is a cast?

Explicit type conversion

Define functional side effect

Functional side effect occurs when the function changes either one of its parameters or a variable.

How does operand evaluation order interact with functional side effects?

If the language does not allow functional side effects then the order of evaluating the operands has no effects on the value of the expression.

In JavaScript, what is the difference between == and ===?

It is the same but === prevent its operands from being coerced.

What is one possible disadvantage of treating the assignment operator as if it were an arithmetic operator?

It provides yet another side effect

Define narrowing and widening conversions.

Narrowing conversion is one that converts an object to a type that cannot include all of the values of the original type. e.g. float to int Widening conversion is one in which an object is converted to a type that can include at least approximations to all of the values of the original type. e.g., int to float

Should an optimizing compiler for C or C++ be allowed to change the order of subexpressions in a boolean expression? Why or why not?

No, because of short circuit evaluation, the order of subexpressions around an && is important.

Would it be a good idea to eliminate all operator precedence rules and require parentheses to show the desired precedence in expressions? Why or why not?

No, this would make it very difficult to read.

What is a prefix operator?

Operator that precede their operands

What is a ternary operator?

Operator with three operands

When might you want the compiler to ignore type differences in an expression?

Suppose Type1 is a subrange of Integer. It may be useful for the difference between Type1 and Integer to be ignored by the compiler in an expression.

Define operator precedence and operator associativity.

The operator precedence rules for expression evaluation define the order in which "adjacent" operators of different precedence levels are evaluated. Associativity- when an expression contains two adjacent occurrences of operators with the same level of precedence

What is an overloaded operator?

Use of an operator for more than one purpose


Conjuntos de estudio relacionados

Chapter 14: Users, Groups, and Permissions

View Set

A&P Chapter 9 Muscles and Muscle Tissue - Practice Test

View Set

Management Science 590 - Chapter 07

View Set

Physical Science Chapter 11 Study Guide

View Set