It's about life

Chapter 6

Data Types

Assignment from Tri Djoko Wahjono

Review Questions

1. What is a descriptor?

A descriptor is the collection of attributes of a variable.

4. Describe the three string length options.

There are three string length options:

– 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.

7. In what ways are the user-defined enumeration types of C# more reliable than those of C++?

C# enumeration types are never coerced to integer, and the operations of the enumeration types are restricted to particular enumeration types, including the restriction for range of that type. Therefore, C# has more specific enumeration types and not mixed up with integer, which makes it more reliable.

12. What languages support negative subscripts?

Ruby and Lua support negative subscripts.

14. What array initialization feature is available in Ada that is not available in other common imperative languages?

That initialization feature is the “arrow”, which can directly assign values to the array to an index position using the => operator, or set other arrays than the set ones to some values. For example, consider an array Ar: array(1..5) of Integer := (1=>4, 4=>1, other=>0). Then the array will have (starting from index 1) values of 4,0,0,1,0.

17. Define row major order and column major order.

Row major order is the mapping of multidimensional arrays such that the elements of the array that have their first subscript the lower bound value of that subscript are stored first, followed by the elements of second value of the first subscritpt and so on.

Column major order, on the other hand, is the mappng of array such that the elements of an array that have as their last subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the last subscript, and so on

23. What is the primary difference between a record and a tuple?

A tuple is similar to a record, but do not have names for their constituent parts.

38. What is a C++ reference type, and what is its common use?

C++ reference type is a constant pointer that is always implicitly dereferenced. Its common use is to provide for two-way communication between the caller function and the called function.

43. What is a compatible type?

A compatible type is one that is either legal for the operator or allowed under language rules to be implicitly converted by compiler generated code to a legal type.

44. Define type error

Type error isthe application of the operator to an operand of an inappropriate type.

47. What is a nonconverting cast?

A nonconverting cast is the kind of conversion that no actual conversion takes place, just merely a means of extracting the value of a variable of one type and using it as if it were of a different type.

49. Why C and C++ is not strongly typed?

Both of them include union types, which are not type checked.

50. What is name type equivalence?

Name type equivalence is when two variables are defined either in the same declaration or in declarations that use the same type name, the two variables have equivalent types.

51. What is structure type equivalence?

Structure type equivalence is when two variables have identical structures means two variables have equivalent types.

54. For what types does C use structure type equivalence?

C uses structure type equivalence for struct, enum, and union.

Problem Set

2. How are negative integers stored in memory?

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.

6. Compare the use of Boolean data types C++ and Java. Give emphasis on their use in conditional statements and conditional loops.

Basically, both data types indicates the value true / false. In C++, the name is bool while in Java it’s Boolean. Boolean values and expressions are used to determine a condition statement or loop. The main difference is that Boolean in Java can only have values true/false, while in C++, other than true/false, integer values can be used to represent true/false statement – the value 0 is false and other values are considered as true.

9. C provides to derived data types both for name and structure type equivalence: struct and union. Make a study on when to use struct type variable and union type variables!

If all data members of the variables are to be used at once, then struct type variables are required, otherwise union type variables should be used.

17. What kind of conversion is called a nonconverting cast ? Explain with an example in Ada language.

Nonconverting cast is a conversion which happen between types of the same storage size.
Example :
type Source (<>) is limited private;
type Target (<>) is limited private;
function Ada.Unchecked_Conversion (S : Source) return Target;

21. In what way is dynamic type checking better than static type checking?

Dynamic type checking is done at compile time instead of run time, so dynamic type checking allows programmers to be more flexible. Moreover, static type checking do corrections later, which runs during runtime, and this is more costly compared to the dynamic type checking.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


This entry was posted on April 8, 2013 by and tagged .
April 2013
« Mar   Jun »

Blog Stats

  • 6,909 hits
%d bloggers like this: