Data Types Flashcards

(42 cards)

1
Q

Language Evaluation Criteria

A

Readability: the ease with which programs can be read and understood.
Writability: the ease with which a language can be used to write programs.
Reliability: performs to its specifications.
Cost: the ultimate total cost.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some language design trade-offs?

A

Reliability vs Cost. (e.g. java checks that all references to array elements are properly index, increasing execution cost.)
Readability vs Writability. (e.g. APL has many powerful operators that allow complex computations but lacks readability.)
Writability vs Reliability. (e.g. C++ pointers are powerful/flexible but unreliable).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Data Type

A

Defines a collection of data objects and a set of predefined operations on those objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Type Checking

A

The activity of ensuring that the operands of an
operator are of compatible types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Type Error

A

The application of an operator to an operand of an
inappropriate type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Strongly Typed

A

The quality of a program that type errors are always identified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Type System

A

Defines how a type is associated with each expression in the
language and includes its rules for type equivalence and type compatibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are some uses of the type system of a programming language?

A

Error detection, ensuring consistency of the interfaces among modules, and documentation of a program’s data and behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Descriptor

A

The collection of the attributes of a variable that
are used for type checking and performing allocation and deallocation operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Descriptors of Static Attributes

A

Only needed at compile time, built as part of the symbol table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Descriptors of Dynamic Attributes

A

Must be used and maintained by the run-time system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Data types or either…

A

scalar or structured.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Scalar Types

A

Ordinal types (e.g. integer, char, enumerated), real, complex, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Structured Types

A

Records/classes, unions, arrays, pointers, lists, sets, and files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Primitive Data Types

A

Not defined in terms of other data types. Includes numeric (e.g. integer, floating point, complex, and decimals), Boolean, and character types. Some primitive data types are mere reflections of hardware. Others require little non-hardware support for implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

sizeof Operator

A

A unary operator in C++ that determines the size of an operand in bytes, the operand being either a variable name or a data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Primitive Data Type: Integer

A

Almost always a reflection of hardware; mapping is trivial. C/C++ integers include char, short, int, long, long long (non-decreasing order). Java integers include byte, short, int, long (1, 2, 4, 8 bytes respectively). An integer can be made positive or negative by using one of the bits as a sign bit. C++ allows the declaration of unsigned integers.

18
Q

Primitive Data Types: Floating Point

A

Approximations of real numbers. IEEE Floating-Point Standard 754 made floats = sign * mantissa * 2^exp, where mantissa = 1.fract. C++ includes float, double, and double long (increasing order).

19
Q

Primitive Data Types: Boolean

A

Either true or false. Can be implemented in bits but is often implemented in bytes for readability. Allowable operators for Booleans are logical (!, &&, ||) and relational operators.

20
Q

Primitive Data Types: Character

A

Stored as numeric codings, most commonly ASCII (128 characters) or extended ASCII (256 characters). In C++, char is a 1-byte ASCII coding. A byte in Java is an 8-bit quantity. Alternatives include 16-bit coding: Unicode (USC-2 or UFT-16) (Originally used in Java, where a char was a 16-bit quantity. In C++, data type wchar_t is used for Unicode characters) and 32-bit Unicode (USC-4 or UTF-16) (Supported by Fortran since 2003).

21
Q

Character String Types

A

Sequence of characters. Design issues involve whether strings are primitive or not and whether string length is static or dynamic. In C/C++, strings are not primitives. C uses char arrays while C++ has a string class. Fortran and Python have a primitive string type. Java provides its own string class (sequence of Java char) using UTF-16 encoding.

22
Q

What are typical operations for strings?

A

Assignment, copying, concatenation, substring reference, and pattern matching.

23
Q

What are some character string length options in different programming languages?

A

Static: Java’s string class, C++ standard string class, and Python strings.
Limited Dynamic Length: C/C++ allows a special character to indicate the end of a string as opposed to maintaining a string’s length.
Dynamic: SNOBOL4, Perl, JavaScript.

24
Q

Enumeration Types

A

Internally represent values as constant integers. An enumeration is not allowed to appear in more than one type definition and can be coerced into an integer in C++. However, other types cannot be coerced into an enumerated type. Aids in readability and reliability.

25
Pointers
Has a range of values that consists of memory addresses and NULL (value of 0). Pointers indicate the memory address of a variable. Provide a way to manage dynamic memory (allocation and deallocation). In C/C++ pointers are extremely flexible and allows pointer arithmetic but must be used with care.
26
Indirect Addressing
Accessing a variable in two steps by first using a pointer variable that gives the location of the variable.
27
Direct Addressing
Accessing a variable in one step by using the variable name.
28
Dangling Pointers
Dangling pointers point to memory in the heap that was deallocated; they are dangerous as they contain garbage and lead to unpredictable code. This can be resolved by making the pointers NULL.
29
Reference Type
A special pointer type that refers to an object or a value in memory and is used for formal parameters. It has the advantages of both pass-by-reference and pass-by-value. In C++, references must be initialized when declared: int x; int &xr = x; It cannot be reassigned, dereferenced with *, reference another reference, and cannot have a pointer to itself.
30
What are the two types of references in C++ and how can they be declared?
l-value and r-value references. l-value references can be declared using '&' while r-value references can be declared using '&&'.
31
What are the uses of l-value references?
l-value references can be used for aliasing complicated names, using in range for loop statements, and avoiding copy objects for parameter and function returns.
32
How are pointers similar to go-to statements?
They both widen the range of references memory cells that can be accessed by a variable.
33
What are valid array index types in different languages?
C and FORTRAN only allow integers for indexes, Java only allows integer types, and C++ allows ordinal types such as char, int, long, or bool.
34
Indexing/Subsrcipting
A mapping from indices to elements.
35
Index Range Checking
C, C++, FORTRAN, and Perl do not have range checking, but Java and C# does.
36
Array Binding Categories
Static: Ranges are statically bound and storage allocation is static (before run-time and more efficient). Fixed Stack-Dynamic: Subscript ranges are statically bound but allocation is done during run-time. Fixed Heap-Dynamic: Same as fixed stack-dynamic but storage binding is dynamic but fixed after allocation and storage is allocated to the heap. Heap-Dynamic: Binding of subscript ranges and storage allocation is dynamic and can change a number of times.
37
C/C++ Fixed Heap-Dynamic Arrays
C allows fixed heap-dynamic arrays through malloc and free for allocation and deallocation. C++ allows fixed heap-dynamics through the use of new and delete.
38
Arrays in Java
In Java all non-generic arrays are fixed heap-dynamic. There is also a generic second array class ArrayList for dynamic heap-dynamic.
39
Type Checking
The activity of checking that the operands of the operator are of compatible types.
40
Compatible Types
Either legal for the operator or is allowed under language rules to be implicitly converted by the compiler to a legal type.
41
Type Error
The application of an operator to an operand of an inappropriate type.
42
Strongly Typed
Used to refer to languages where type errors are always detected. Coercion rules like in C++ can weaken strong typing considerably.