Senin, 08 April 2013

Chap 7 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta


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

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.

Chap 6 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta



Chapter 6 Review Question and Problem Set
Review Question
1. What is descriptor?
Answer:
Descriptor is a collection of the attributes of a variable that space in a memory what stores the attribute

2.  What are the advantage and disadvantage of decimal data type?
Answer:
Advantages:
- More precise calculation
- increase the ability to show a portion
Disadvantages:
- The range of precision in a value is limited because no exponent is allowed
- Ambiguous sign of decimal (in some standard decimal represent with coma others with period)

4. Describe the three string length option
Answer:
 - Static length string
The length of the string is set when the string is created and it is always static.
-Limited dynamic length string
This kind allows string to have varying length up to a declared and fixed maximum set by the variable’s definition.
- Dynamic length string
This option allows string to have varying length with no maximum limit such as JavaScript.

8. What are the design issues for arrays?
Answer:
The design issues for array are:
• What types are legal for subscripts?
• Are subscripting expressions in element references range checked?
• When are subscript ranges bound?
• When does array allocation take place?
• Are ragged or rectangular multidimensional arrays allowed, or both?
• Can arrays be initialized when they have their storage allocated?
• What kinds of slices are allowed, if any?

10.  What happens when a nonexisted element of an array is referenced in Perl?
Answer:
A reference to nonexisted  element in Perl gives a result of undef but no error is reported.

13. What languages support array slices with stepsizes?
Answer:
Python, Perl and Ruby are the languages that support array slices with stepsize

17. Define row major order and column major order
Answer:
 Row major order is the way where the array that have as their first subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the first subscript, and so forth.
Column major order is the way where the elements of an array that have as their last subscript the power bound value of that subscript are stored first, followed by the elements of the second value of the last subscript, and so forth.

21. What is the purpose of level numbers in COBOL record?
Answer:
The purpose of level numbers in COBOL record is to indicate their relative values of the hierarchal structure of the record.

22. Define fully qualified and elliptical reference to field in records.
Answer:
fully qualified all the intermediate names, from the largest enclosing record to the specific field, are named in the reference.
Elliptical reference is a method where enclosing record names can be omitted as long as the resulting reference is unambiguous.

24. Are the tuples of Python mutable?
Answer:
 the tuples of Python is inmmutable.

25. What is the purpose of an F# tuple pattern?
Answer:
The purpose of an F# tuple pattern is to make a multiple assignment by using the let statement

32. What are the design issues for unions?
Answer:
design issues for unions are:
-Should type checking be required? Note that any such type checking must be dynamic.
-Should unions be embedded in records?

35. What are the design issues for pointer types?
Answer:
The design issues of pointer types are
• What are the scope and lifetime of a pointer variable?
• What is the lifetime of a heap-dynamic variable (the value a pointer references)?
• Are pointers restricted as to the type of value to which they can point?
• Are pointers used for dynamic storage management, indirect addressing, or both?
• Should the language support pointer types, reference types, or both?

44. Define type error.
Answer:
Type error is an application that checks errors from operand to an operand.

45. Define strongly typed.
Answer:
Strongly typed is a method when the type error are always detected.

Problem Set

1. What are the arguments for and agonists four signed integer sizes in Java?
Answer:  Java defined int as a 32-bit number in the other hand C have either 16 or 32 bits dipending in the implementation. Four byte signed integer in java provide a large range that is enough to hold the information you need. But beside that capability, compared with int in C that only takes 2 byte fot int, the 4 byte signed integer in java takes more memory. Java defined int as a 32-bit number in the other hand C have either 16 or 32 bits dipending in the implementation.

2. How are negative integers stored in memory?
Answer: negative integer stored in memory by turning the value into binary and makes the compliment of its binary.
For example : integer 1 in binary is 0001 to get -1 the computer uses the compliment so it will be 1110. The 1110 binary might be 14 or -1 depends on the data type.

7. Compare the pointer and reference type variable in C++
Answer: pointer can be used to point the memory location of a variable and it can also assign the values to the memory location. It is quite similar with reference but in reference, only the value that is passed not the memory location. For example
int main ()
{
  int a, b;
  int *pointer;

  pointer = &a;
  *pointer = 10;
  pointer = &b;
  *pointer = 20;
printf("a is:  %d\n", a);
printf("b is: %d", b);
  return 0;
}
The output will be 
a is: 10
b is: 20
the pointer assign the value of 10 the memory location of variable pointer and it is referenced to a so the output is 10.

8. What are the differences between the reference type variable of C++ and those of Java?
Answer: The differences between the reference type variable of C++ and those of Java are first in Java we can’t actually get to and manipulate the underlying value of a reference in Java but in C we can manipulate it. Second in java references are strictly controlled than in C. Third in Java reference will be implemented as pointers, but that is not required by the specification in the other hand C reference is not implemented as pointer.

19. Any type defined with typedef is type equivalent to its parent type.
How does the use of typedef differ in C and C++?
Answer
Typedef in C uses struct to do typedef, with the fortmat typedef struct name_of struct; Typedef in c++ we don’t need to uses the keyword typedef and it has a format typedef existing_type new_type_name


21. In what way dynamic checking is better than static type checking?
Answer: Dynamic checking occurs when type information is used at runtime. In the other hand static type checking means that type checking occurs at compile time. It is better to do dynamic checking because it will be more reliable and more relevant to the information that is used during the runtime


Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

chap 5 review question and problem set concepts of programming language sebesta


Chapter 5 Review Question and Problem Set

Review Question

2. What is the potential danger of case sensitive names?
Answer:
The potential danger of case sensitive is the ambiguity between the user and the program. For example with case sensitive variable the name of variable “Angka” and “angka” has the different meaning for machine but the same meaning for user.

3. In what way are reserved words better than keyword?
Answer:
 Reserved words are better than keyword because reserved word cannot be used as the name and it can also be used to redefine keywords.

7. Define binding and binding time
Answer:
binding is association in a program it could be between variable and its type or operation and symbol. Binding time is the time that is taken to associate (binding).

9. Define static binding and dynamic binding.
Answer:
Static binding is binding that happen before run time and it still remains unchanged throughout program execution. Dynamic binding is binding that happen during the run time and it might change in the program execution.

16. What is referencing environment of a statement
Answer:
referencing environment of statement is the collections of all variable that are visible in the statement.

18. What is block?
Answer:
In programming block is a section where variable and statement are allocated.

Problem Set

1. Decide which of the following identifier names is valid in C language.
Support your decision.
_Student
int
Student
123Student
Student123
Answer:
the valid identifier names in C language are _Student, Student and Student123 because the valid identifier names in C should not be integer in beginning, reserved word (int, float, etc.) and it doesn’t contain space.

2. What is l-value? Write a statement in C language which gives the compile time error “l-value required”.
Answer: l
-value is an expression that refer to memory location.
int main()
{
    int arr[]={1,2,3};
    int i;
    for(i=0;i<3;i++)
    {
        printf("\n%d",*arr);
        arr++;
    }
    return 0;
}

4. Why is the type declaration of a variable necessary? What is the value range of the int type variable in Java?
Answer:
Declaration of a variable is necessary because it define the type of the variable that declared which make the variable unambiguous. The range value of int type variable in java is 2.147.483.648 to 2.147.483.647.

Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.