An assignment from Mr. Tri Djoko Wahyono (as always). As what the title said, it is the answer for some question (6 numbers, quite randomly in Review Qustion and 3 numbers in Problem Set) in Chapter 5 in "Concept of Programming Language" book.
Review Question
1. What are the design issues for names?
- Are names case sensitive?
- Are the special words of the language reserved words or keywords?
The potential danger of case-sensitive names is its readability, because names that look very similar in fact denote different entities.
3. In what way are reserved words better than keywords?
Reserved words are better than keywords because the ability to redefine keywords can be confusing.
7. Define binding and binding time?
Binding is an association between an attribute and an entity, such as between a variable and its type or value, or between an operation and a symbol.
9. Define static binding and dynamic binding.
It is a static binding if it first occurs before run time begins and remains unchanged throughout program execution. If the binding first occurs during run time or can change in the course of program exception, it is called dynamic binding.
23. What are the advantages of named constants?
Named constants are useful as aids to readability and program reliability.
Problem Set
1. Decide which of the following identifier names is valid in C language. Support your decision.
a. _Student
b. int
c. Student
d. 123Student
e. Student123
For (a), (b), and (d), are an invalid variable names, because in C language, a variable name can't :
> Begin with special characters (@,(,),_, etc.).
> Same as reserved words or keyword (such int, char, main, etc.).
> Begin with number.
7. Assume the following JavaScript program was interpreted using static-scooping rules. What value of x is displayed in function sub1? Under dynamic-scooping rules, what value of x is displayed in function sub1?
Under static-scooping rules, the value of x which is displayed is 5.
Under static-scooping rules, the value of x which is displayed is 10.
10. Consider the following C program:
void fun (void) {
int a, b, c; /*definition 1*/
. . .
while(. . .) {
int b, c, d; /*definition 2*/
. . . <------ 1
while(. . .) {
int c, d, e; /*definition 3*/
. . . <------ 2
}
. . . <------ 3
}
. . . <------ 4
}
For each of the four marked points in this function, list each visible variable, along with the number of the definition statement that defines it.
Point 1 : a, b, and c of definition 1.
Point 2 : a of definition 1 - b of definition 2 - c, d, and e of definition 3.
Point 3 : a of definition 1 - b, c, and d of definition 2.
Point 4 : a, b, and c of definition 1.
No comments:
Post a Comment