Concepts of Programming Languages Chapter 6
Name : Erland
NIM : 1601218035
Lecturer : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment : Concept of programming languages Chapter 6
Review Questions
1. What is a descriptor?
Answer : A descriptor is the collection of the attributes of a variable.
2. What are the advantages and disadvantages of decimal data type?
Answer :The advantages is able to precisely store decimal value, at least
those within a restricted range, which cannot be done with
floating-point. The disadvantages of decimal data types are
that the range of value is restricted because no exponents are
allowed, and their representation in use is restricted.
those within a restricted range, which cannot be done with
floating-point. The disadvantages of decimal data types are
that the range of value is restricted because no exponents are
allowed, and their representation in use is restricted.
3. What are the design issues for character string types?
Answer : - Should strings be simply a special kind of character array
or a primitive type?
- Should strings have static or dynamic length?
or a primitive type?
- Should strings have static or dynamic length?
4. Describe the three string length options.
Answer :
- Static length string: the length is static and set when created
- Limited dynamic length string: the length can vary up to the declared and fixed maximum set by the variable’s definition.
- Dynamic length string: The length varies without maximum. Stored in dynamic storage.
5. Define ordinal, enumeration, and subrange types.
Answer : An ordinal type is one i which the range of possible values
can be easily associated with the set of positive integer.
Enumeration type is one in which all the possible values,
which are named constants, are provided, or enumerated,
in the definition.
A subrange type is a contiguous subsequence of an ordinal type.
can be easily associated with the set of positive integer.
Enumeration type is one in which all the possible values,
which are named constants, are provided, or enumerated,
in the definition.
A subrange type is a contiguous subsequence of an ordinal type.
6. What are the advantages of user-defined enumeration types?
Answer:Enumeration types can provide advantages in both readibility
and reliability.
Answer:Enumeration types can provide advantages in both readibility
and reliability.
7. In what ways are the user-defined enumeration types of C# more reliable
than those of C++?
than those of C++?
Answer : C++ enumeration constants to be assigned to variables of any
numeric type. in C# enumeration types are defined as new types
with datatype declarations.
numeric type. in C# enumeration types are defined as new types
with datatype declarations.
8. What are the design issue for arrays?
Answer : - What types are legal for subscripts?
- Are subscripting expressions in element reference range checked?
- When are subscript range bound?
- When does array allocation take place?
- Are ragged or rectangular multidimensioned arrays allowed?
- Can arrays be initialized when they have their storage allocated?
- What kinds of slices are allowed, if any?
12. What languages support negative subscripts?
Answer: Ruby and Lua
- Are subscripting expressions in element reference range checked?
- When are subscript range bound?
- When does array allocation take place?
- Are ragged or rectangular multidimensioned arrays allowed?
- Can arrays be initialized when they have their storage allocated?
- What kinds of slices are allowed, if any?
12. What languages support negative subscripts?
Answer: Ruby and Lua
17. Define row major order and collumn major order.
Answer:
Row major order is the mapping of multidimensional arrays such thatthe elements of the array that have their first subscript the lower boundvalue of that subscript are stored first, followed by the elements of secondvalue of the first subscritpt and so on.Column major order, on the other hand, is the mappng of array such thatthe elements of an array that have as their last subscript the lower boundvalue of that subscript are stored first, followed by the elements of the secondvalue of the last subscript, and so on
Problem Sets
1. What are the arguments for and againts four signed integer sizes in java?
Answer: bytes(1 byte), short(2 bytes), integer(4 bytes), long(8 bytes).
depending on the domain of the variable required, data types are used.
depending on the domain of the variable required, data types are used.
2. How are negative integers stored in memory?
Answer: In the number, the leftmost bit is considered as a “sign bit”,
which signifies whether the integers are negative or not. If it’s
negative, then that bit must store 1, and 0 otherwise.
7. Compare the pointer and reference type variable in C++
Answer: A C++ reference type variable is a constant pointer that is always
implicity deferenced.
8. What are the differences between the reference type variable of C++ and
those of Java?
Answer:In their quest for increased safety over C++, the designers of Java
removed C++-style pointers altogether. Unlike C++ reference variables,
Java reference variables can be assigned to refer to different class
instances; they are not constants. All Java class instances are referenced
by reference variables. That is, in fact, the only use of reference variables
in Java.
Answer: A C++ reference type variable is a constant pointer that is always
implicity deferenced.
8. What are the differences between the reference type variable of C++ and
those of Java?
Answer:In their quest for increased safety over C++, the designers of Java
removed C++-style pointers altogether. Unlike C++ reference variables,
Java reference variables can be assigned to refer to different class
instances; they are not constants. All Java class instances are referenced
by reference variables. That is, in fact, the only use of reference variables
in Java.
21. In what way is dynamic type checking better than static type checking?
Answer : Static checking reduces programmer flexibility.
Answer : Static checking reduces programmer flexibility.