Chapter
7 Review Question and Problem Set
Review
Question
3. What is prefix operator?
Answer:
prefix operator is an
operator that precedes their operands.
5. What is nonassociative operator?
Answer:
are operators that have no
defined behavior when used in sequence in an expression.
8. Define functional
side effect
Answer: functional side effect is a condition when the
function changes either one of its parameters or global variable.
14. What is mixed –mode
expression?
Answer:
mixed-mode
expression is the condition whether an operator can have operands of different
types.
18. What is short-circuit
evaluation?
Answer:
Short circuit evaluation
is one in which the result is determined without evaluating all of the operands
and/or operators.
20. How does C support relational and Boolean expression?
Answer:
C support relational and
Boolean expression by using the sign of >, >=, <, <= and == to
express the relational and uses the variable type of Boolean to assign true or
false or can be represented as 1 for true and 0 for false.
28. What is cast?
Answer:
Cast is explicit type
conversions in C-based language.
Problem
Set
2. State your own arguments for and against allowing
mixed-mode arithmetic expression
Answer:
Mixed mode arithmetic can
be helpful when the statement is in a complex expression, so it will be faster
to write in the mixed mode arithmetic expression, but in the other hand mixed
mode arithmetic will be very confusing and could increase the change of error.
5. Should C’s assigning operations (for example, +=) be
included in other language (that do not already have them)? Why or why not?
Answer:
Yes it should be added
to other programming language that doesn’t have it yet because the assigning
operation is really useful in “for” looping and in recursion. So the addition
of assigning operation will increase the orthogonality of its language.
6. Should C’s single-operand assignment form (for example
++count) be included in other language (that do not already have them)? Why or
why not?
Answer:
No it shouldn’t be
added, because the use of assigning operation can be replaced the
single-operand assignment so it doesn’t increase the complexity of its language
for example the use of x++ can be replace with x+=1
for example the use of x++ can be replace with x+=1
7.
Describe a situation in which the add operator in a programming language would
not be commutative.
Answer:
When we use add operator to combined strings. Such as “makan”+”malam”=
makanmalam and not equal to “malammakan” = “malam”+”makan”
8. Describe a
situation in which the add operator in a programming language would not be
associative.
Answer:
in the
situasion when we add three number with different signed integer in java
-2,147,483,648
to 2,147,483,647 and 1 so it would be
(-2,147,483,648+2,147,483,647)+1
= -1+1 = 0
-2,147,483,648+(2,147,483,647+1)
= -2,147,483,648 + (error)
13. Let the function fun be
defined as:
int fun (int *k){
*k += 4;
return 3 * (*k) – 1;
}
suppose fun is used in a
program as follows:
void main(){
int i = 10, j = 10, sum1, sum2;
sum1= (i / 2) + fun( &i );
sum2 = fun ( &j ) + (j /
2);
}
What are the values of sum1 and
sum2
a. if the operands in the
expressions are evaluated left to right?
sum1 is 46; sum2 is 48
b. if the operands in the
expressions are evaluated right to left?
sum1 is 48; sum2 is 46
Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.