Variables and Data Types in Programming, Exams of Programming Languages

A comprehensive overview of variables and data types in programming. It covers characteristics of variables, including name, address, value, type, lifetime, and scope. The document explores l-value, r-value, binding, static and dynamic binding, and the role of data types in determining value range and operations. It examines primitive, ordinal, enumeration, sub-range, array, record, pointer, and reference data types. The document also discusses type checking, type errors, strongly typed languages, expressions, assignment statements, operators, operator precedence, functional side effects, declarative functions, operator overloading, type conversion, and relational and boolean expressions. This comprehensive coverage provides a solid foundation for understanding fundamental programming concepts.

Typology: Exams

2023/2024

Available from 06/25/2024

benz-mickey
benz-mickey 🇺🇸

5

(2)

1.2K documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Theory Programming Languages2/ 90
Question with Verified Answers/ 2024-
2025.
variables are characterized by: - Answer: name
address
value
type
lifetime
scope
aliases - Answer: if two variable names can be used to access the same memory
location
1 | P a g e
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Variables and Data Types in Programming and more Exams Programming Languages in PDF only on Docsity!

Theory Programming Languages2/ 90

Question with Verified Answers/ 2024-

variables are characterized by: - Answer: name address value type lifetime scope aliases - Answer: if two variable names can be used to access the same memory location

l-value - Answer: the variable's address r-value - Answer: the variable's assigned value binding - Answer: an association between an attribute and an entity (binding of a data type to a variable, value to a variable, operation to a symbol) static binding - Answer: if binding occurs before runtime and remains unchanged through the program execution dynamic binding - Answer: if binding occurs during execution or can change during execution of the program data types determines: - Answer: the range of values of variables the set of operations defined for that type explicit declaration - Answer: a program statement used for declaring variable types (int x;) implicit declaration - Answer: a default mechanism for specifying types of variables (the first appearance of the variable in the program, FORTRAN and Perl) type inferencing - Answer: determine the data types of variables (Java ArrayList)

heap memory - Answer: allocated on request, de-allocated on request or by garbage collection program and static variables - Answer: fixed at load time, bound to memory cells before execution begins and remains bound to the same memory cell throughout execution variable scope - Answer: the range of statements over which the variable is visible non-local variables - Answer: variables that are visible but not declared in the program unit (method or function) global variable - Answer: A variable whose scope is "global" to the program, it can be used and updated by any part of the code. Its global scope is typically derived from the variable being declared (created) outside of any function, object, or method. static lexical scope - Answer: variables can be hidden from a unit by having a "closer" variable with the same name (Java this.num = num) dynamic lexical scope - Answer: based on calling sequences of program units, not their textual layout, references to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point

referencing environment - Answer: the collection of all names that are visible when executing the statement, the referencing environment consists of a function's local variables and parameters, as well as the static and dynamic scoped language named constant - Answer: a variable that is bound to a value only when it is bound to storage data type - Answer: defines a collection of data objects and a set of predefined operations on those objects descriptor - Answer: the collection of the attributes of a variable primitive data types - Answer: data types not defined in terms of other data types (CLOSE to being implemented directly by hardware) PDT: Integer - Answer: almost always an exact reflection of the hardware: int, long, byte, short PDT: Floating Point - Answer: models real numbers, but only as approximations: float and double PDT: Decimal - Answer: for business applications only

array indexing - Answer: (sub-scripting) a mapping from indices to elements, FORTRAN/Ada uses parenthesis arr(i), most other languages uses brackets arr[i] heterogeneous array - Answer: array in which the elements need not be of the same type (Perl, Python, JavaScript) rectangular array - Answer: rectangular matrix is a two-dimensional array in which all of the rows must have the same number of elements jagged array - Answer: jagged matrix has rows or columns that might vary in the number of elements, possible when multi-dimensional arrays actually implemented as arrays of arrays array slices - Answer: some substructure of an array (sub array) row major array - Answer: arrays stored as first row, second row, etc. Location (a[i,j]) = address of a [row_lb,col_lb] + (((i - row_lb) * n) + (j - col_lb)) * element_size column major array - Answer: FORTRAN stores arrays as column one, column two, etc associative array - Answer: an unordered collection of data elements that are indexed by an equal number of values called keys, user defined keys must be stored (Perl, Python, Ruby)

record types - Answer: a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names pointer types - Answer: has a range of values that consists of memory addresses and a special value, nil (or null), provide a way to dynamically access heap memory dangling pointers - Answer: pointer points to a heap-dynamic variable that has been de-allocated memory leakage - Answer: the process of losing heap-dynamic variables reference types - Answer: types that store references to objects, or instances of classes. Reference types are sometimes called class types because they are the names of classes. String, Scanner, and System are all examples of reference types. type checking - Answer: the activity of ensuring that the operands of an operator are of compatible types, also applies to checking that arguments of subprogram are compatible with parameters, and applies when we think of assignment (=) as an operator type error - Answer: the attempted application of an operator to an operand of an inappropriate type

postfix operator - Answer: operator that procedes the operands (Java i++) operator precedence - Answer: rules for expression evaluation define the order in which "adjacent" operators of different precedence levels are evaluated. parentheses unary operators ** (exponentiation, if the language supports it) *, / +, - operator associativity - Answer: rules for expression evaluation define the order in which adjacent operators with the same precedence level are evaluated, can be overridden with parenthesis conditional expressions - Answer: if, else blocks. can also be written as -> average = (count == 0)? 0 : sum / count interpreted the same as -> if (count == 0) average = 0 else average = sum /count functional side effects - Answer: when a function changes a two-way (e.g., C++ reference) parameter or an ancestor variable

declarative function - Answer: a function that for given input parameter values always returns the same value function written in declarative style - Answer: function without any assignment statements,either explicit or implicit via changes to mutable data structures operator overloading - Answer: Use of an operator for more than one purpose type conversion - Answer: (coercion - implicit or auto type conversion) (casting - explicit type conversion C (int) angle) narrowing type conversion - Answer: converts an object to a type that cannot include (even approximations to) all of the values of the original type (float to int) widening type conversion - Answer: an object is converted to a type that can include at least approximations to all of the values of the original type (int to float) relational expressions - Answer: expressions using relational operators (>, <, =, ...). operands can be strings or numbers, expression evals to a bool value (C 0 or 1) boolean expressions - Answer: expressions using boolean operators (AND, OR, NOT), operands are boolean and the result is boolean. operator precedence - Answer: arithmetic relational

continue statement - Answer: skips the remainder of the loop iteration (Ruby next) iterator - Answer: control mechanism is a call to an iterator function that returns the next element in some chosen order, if there is one; else loop is terminated Java iterator - Answer: any class implementing java.util.Iterator interface. next() returns the next element, hasNext() returns a bool indicating whether there is remaining data, Iterator() method returns an iterator object