

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


b. [5 pts.] The fact that parameters are passed by value in C means that a function parameter is a copy of the argument which is used in the call. The behavior that results is that a function can change the value of a parameter, and it has no effect upon the argument that was used in the call. (Note: the reason that array parameters act differently has now been explained in class, but had not been emphasized as of the exam date.)
c. [4 pts.] Portability refers to the property that a program has when it’s able to work when compiled on a different machine, or using a different compiler, and work right without modification. C has more issues with portability than Java because the C language standard leaves a lot more decisions up to the compiler writer (primarily for efficiency purposes), such as sizes of data types, evaluation order of expressions, etc., whereas Java mandates specific choices for such issues.
d. [5 pts.] A side effect occurs when, in the process of evaluating an expression, something is changed as a result– such as a variable’s value being modified, or something being read or printed. (Note in particular that expressions, not statements, have side effects.) Assignments, the assignment operators, and the unary increment and decrement operators all produce values in C, so they’re expressions but cause side effects, so any example using them would illustrate a side effect, such as a= 3, b += 4, or c++, or d= e++. Also note: side effects are not in and of themselves inadvertent as some answers said, in fact, unless the programmer made a mistake, they are entirely intentional. If a programmer wrote the statement a= 3 or d= e++, then he or she intended a’s value, or d’s and e’s values, to be modified in the process of evaluating the expressions.
a. 8 1
b. 7 1
c. 1 0
d. 5 6 24
e. 3
f. -11 15 3. Note: although some answers said that C has no unary negation operator, note that it was mentioned and illustrated in class (see slide 45 from Lecture #06), and it’s mentioned in Chapter 5 of the text,
g. 2.250000 4
while (ul > 0) { ul >>= 1; size++; }
return size / 8; }
int sizeof_long(void) { unsigned long ul= 1; int size= 0;
while (ul != 0) { ul <<= 1; size++; }
return size / 8; }
Note that the bitwise shift operators << and >> do not change their operands’ values. As explained during lecture, only a few operators in C modify any of their operands, and the bitwise shift operators are not among them.