Org Ch6(Data Types)
What is a compatible type?
A compatible type is one that either is legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code to a legal type.
Define strongly type.
A programming language is strongly typed if types errors are always detected.
What is a C++ reference type, and what is its common use?
C++ includes a special kind of pointer type called a reference type that is used primarily for formal parameters.
What is the purpose of level numbers in COBOL records?
COBOL uses level numbers to show nested records; others use recursive definition
Define fully qualified and elliptical references to fields in records.
Fully qualified references must include all record names. Elliptical references allow leaving out record names as long as the reference is unambiguous.
What are the advantages of user-defined enumeration types?
The advantages are readability and reliability.
What are the design issues for pointer types?
What are the scope of and lifetime of a pointer variable? What is the lifetime of a heap-dynamic variable? 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?
What are the design issues for arrays?
What types are legal for subscripts? Are subscripting expressions in element references range checked? When are subscript ranges bound? When does allocation take place? What is the maximum number of subscripts? Can array objects be initialized? Are any kind of slices supported?
Why are reference variables in C++ better than pointers for formal parameters?
because a pointer refers to an address in memory while a reference refers to an object or a value in memory.
Why is Java not strongly typed?
because there are no implicit ways type errors can go undetected.
java includes 4 signed integer sizes
byte, short, int, long
What are the design issues for character string types?
-Is it a primitive type or just a special kind of array? - Should the length of strings be static or dynamic?
how many bits does it take to code a decimal digit
4 bits
On what are Python's list comprehensions based?
A list comprehension is an idea derived from set notaion.
What is an aggregate constant?
A parenthesized lists of values.
What is the purpose of an F# tuple pattern?
A tuple pattern is simply a sequence of names, one for each element of the tuple , with or without the delimiting parentheses.
What arrays initialization feature is available in Ada that is not available in other common imperative languages?
Ada provides two mechanisms for initializing arrays in the declarations statements: by listing them in the order in which they are to be stored, or by directly assigning them to an index position using the => operator, which in Ada is called an arrow.
What are the advantages and disadvantages of decimal data types?
Advantage: accuracy Disadvantages: limited range, wastes memory
What is the structure of an associative array?
An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys. User-defined keys must be stored.
Define ordinal, enumeration, and subrange types.
An ordinal type is one in which the range of possible values can be easily associated with the set of positive integers. An enumeration types is an all possible values, which are named constants, are provided in the definition. A subrange types is an ordered contiguous subsequence of an ordinal type.
In what ways are the user-defined enumeration types of C# more reliable than those of C++?
C# enumeration types are like those of C++, except that they are never coerced to integer. So, operations on enumeration types are restricted to those that make sense. Also, the range of values is restricted to that of the particular enumeration type.
What are the two common problems with pointers?
Dangling pointers (dangerous) and Lost heap-dynamic variable.
How does JavaScript support sparse arrays?
Javascript objects are sparse, and arrays are just specialized objects with an auto-maintained length property (which is actually one larger than the largest index, not the number of defined elements) and some additional methods.
Are the unions of Ada always type checked?
No. the user can tell the system when the type checking can be static.
In what primarily imperative language do lists serve as arrays?
Python
Are the tuples of Python mutable?
Python includes an immutable tuple type
Describe the lazy and eager approaches to reclaiming garbage.
Reference counters (eager approach): reclamation is gradual. Mark-sweep (lazy approach): reclamation occurs when the list of variable space becomes empty.
What languages support array slices with stepsizes?
Ruby, Python, Perl.
What are the design issues for unions?
Should type checking be required? Should unions be embedded in records?
Describe the three string length options.
Static length: The length can be static and set when the string is created. compile-time descriptor Limited dynamic length: allow strings to have varying length up to a declared and fixed maximum set by the variable's definition. may need a run-time descriptor for length (but not in C and C++) Dynamic length: allow strings to have varying length with no maximum. need run-time descriptor; allocation/de-allocation is the biggest implementation problem
Define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and heap dynamic arrays. What are the advantages of each?
Static: subscript ranges are statically bound and storage allocation is static (before run-time) Advantage: efficiency (no dynamic allocation). Fixed stack-dynamic: subscript ranges are statically bound, but the allocation is done at declaration time. Advantage: space efficiency . Stack-dynamic: subscript ranges are dynamically bound and the storage allocation is dynamic (done at run-time) Advantage: flexibility (the size of an array need not be known until the array is to be used). Fixed heap-dynamic: similar to fixed stack-dynamic: storage binding is dynamic but fixed after allocation (i.e., binding is done when requested and storage is allocated from heap, not stack). Heap-dynamic: binding of subscript ranges and storage allocation is dynamic and can change any number of times. Advantage: flexibility (arrays can grow or shrink during program execution).
What is the action of the Scheme function CAR?
The CAR function returns the first element of its list parameter.
what is a descriptor
a collection of the attributes of a variable
a length of a string can be varying in length up to a declared and fixed maximum set by the variables definition and called
a limited dynamic length strings
the length of a string can be static and set when the string is created and is called
a static length string
what is precision
accuracy of fractional part of a value, measured as the number of bits
character types used to be called ASCII, an 8 bit code but now
are represented by Unicode, a 16 bit character set
the most common string operations are
assignment, catentation, substring reference, comparison, and pattern matching
C and C++ use char arrays to store
character strings
character types in python are actually
character strings of length 1
enumeration types provide a way of defining and grouping
collections of named constants , which are called enumeration constants
special hardware support is required for
decimal data types
what is a data type
defines a collection of data objects and a set of predefined operations on those objects
the two user defined ordinal types are
enumeration and subrange
boolean types are often used to represent
flags or switches
two common floating point types are called
float and double
character string literals that are built by the compiler also
have the null character to indicate the array has terminated
What happens when a nonexistent element of an array is referenced in Perl?
if you try to append non-existent elements from an array to another one, the initial array will grow as needed, even though the elements to append do not exist.
enumeration constants are typically
implicitly assigned the integer values 0,1,...but can be explicitly assigned any integer literal in the types definition
an enumeration type is one in which all the possible values which are named constants are provided or enumerated
in the definition
what is the most common primitive numeric data type is
integer
in java the primitive ordinal types are
integer, char and boolean
the first field of every static descriptor
is the name of the type
the second field of every static descriptor
is the second field is the type's length(in characters)
What is the action of the F# fuction tl?
it is the methods of the List class, as in List.hd[1; 3; 5; 7], which returns 1
booleans are typically stored in a byte because
it is usually the smallest efficiently addressable cell of memory
an ordinal type is
one in which the range of possible values can be easily associated with the set of positive integers
the string manipulation functions of the C standard library are also available in C++, and are inherently unsafe because they dont guarantee against overflow and so
programmers in C++ should use the string class from the std library rather than char arrays from the C library
the collection of values that can be represented by a floating point type is defined by
range and precision
what is range
range is combination of the range of fractions, and the range of exponents
floating point data types model
real numbers *but the representations are only approximations for many real values
What is the primary difference between a record and a tuple?
record is an aggregate of data elements in which the individual elements are identified by names and accessed through offsets from the beginning of the structure. tuple is a data type that is similar to a record, except that the elements are not named.
how are complex numbers represented in Fortan and Python
represented as ordered pairs of floating point values
static length and limited dynamic length strings
require no special dynamic storage allocation
a character string type are types where the values consist of
sequences of characters
substring references are often called
slices
character strings can be supported directly in hardware but
software usually is used to implement storage, retrieval and manipulation
dynamic length strings require more complex
storage management
run time descriptor for limited dynamic strings require only
storing both the fixed maximum length and the current length
what are the three approaches to supporting the dynamic allocation and deallocation that is required for dynamic length strings
strings can be stored in a linked list strings can be stored as an array of pointers to individual characters allocated in the heap store complete strings in adjacent storage cells
if strings are not defined as a primitive type
strings data is usually stored in arrays of single characters and referenced this way
strings from the String class are immutable but
strings from the StringBuffer class is mutable , more like arrays of singel characters
a subrange type is a contiguous
subsequence of an ordinal type *for example, 12...14 is a subrange of an integer type
the third field of every static descriptor
the address of the first character
What advantages do Java and C# reference type variables have over the pointers in other languages?
the reference Java and C# provide some of the flexibility and the capabilities of pointers, without the hazards.
a length of a string can also be a varying length with no maximum in some languages, such as JS, Perl and C++ and
these are called dynamic length strings
the double type is provided when needed for larger range and usually store
twice as many number of bits
Define type error.
type error is the application of an operator to an operand of an inappropriate type.
Define union, free union, and discriminated union.
union: a type whose variables are allowed to store different type values at different times during execution. free union: provide union constructs in which there is no language support for type checking. Discriminated union: type checking of unions require that each union include a type indicator.
decimal types are stored like character strings
using binary codes for decimal digits (BCD)
the float type is the standard size
usually stored in four bytes of memory
What is nonconverting cast?
when no conversion takes place. It is merely a means of extracting the value of a variable of one type and using it as if it were of a different type.
a descriptor for a static character string type
which is required only during compilation has three fields
most computers store floating points in binary
which only makes approximations worse *0.1 cannot be represented in binary by a finite number of binary digits
Are the unions of F# discriminated?
yes.