PLC Fill In Blank
Why are floating point numbers often not associative?
Overflow problem
True or False? An unconditional branch statement, or goto, transfers control to a specified location in a program.
True
True or False? C# allows the control expression and case labels to be strings.
True
True or False? C# includes both the reference of Java and the pointer of C++.
True
True or False? C# users can define their own collections and write their own iterators.
True
True or False? C's for statements often have empty bodies since all the work can be done in the controlling expressions.
True
True or False? C99 can have a declaration in its first expression.
True
True or False? Every counting loop can be built with a logical loop, but the reverse is not true.
True
True or False? In APL, the order of operator evaluation is determined entirely by associativity, which is right to left for all operators.
True
True or False? In C and C++, pointers can point to a function.
True
True or False? In C, the comma operator can be used to join multiple expressions into a single expression.
True
True or False? In Java, unary plus and minus cause the implicit conversion of short and byte operands to int type.
True
True or False? In PHP's switch statement, the case values can be any scalar types.
True
True or False? In PHP, each array contains an internal pointer to its "current" element.
True
True or False? In Python, elements in a list can be of a different type.
True
True or False? In none of Scheme's COND predicates are true, and there is an ELSE statement, it's expression is evaluated and the value is returned?
True
True or False? In the functional languages ML, F# and Lisp, a selector is not a statement; it is an expression that produces a value.
True
True or False? Java and C# allow only Boolean expressions in if statements.
True
True or False? Lists can be nested.
True
True or False? Lists in Python are mutable.
True
True or False? Pointers in C can point to any variable.
True
True or False? Pointers in PL/I can refer to both heap-dynamic variables and other program variables.
True
True or False? Python and ML can include elements of mixed types.
True
True or False? Python's tuples can be empty.
True
True or False? The exit statements in Java and Perl (i.e. break and last) can specify a label.
True
True or False? The expression -count++ is interpreted as -(count++), not (-count)++.
True
True or False? When a Scheme COND expression that follows the predicate is evaluated it is returned as the value of COND.
True
True or false? A reference type in C++ must be initialized at the time it's bound to storage and cannot refer to any other variable during its lifetime.
True
True or false? All variables in Smalltalk, Python, Ruby and Lua store references and are implicitly dereferenced.
True
True or false? An array name not followed by subscripts can be used as a pointer to the first element of the array
True
True or false? Arithmetic cannot be performed on references.
True
True or false? Operators in Ruby can be overridden.
True
True or false? Perl, Python and Lua do not have multiple-selection statements.
True
True or false? The value of an expression may depend on the order of evaluation of the operators in the expression.
True
True or false? When the heap-dynamic variable is deallocated, the tombstone remains.
True, set to nil
True or False? Java supports associative arrays?
True. As a matter of fact, Perl, Python, Ruby, C++, C# and F# do too.
True or False? Visual Basic's exponentiation operator is left associative.
True. Most languages are right associative
In Scheme, when using COND, the predicates are evaluated in order until one evaluates to ____.
#T
What character does a hash in Perl begin with?
%
How do you get the address of a variable in C?
&
Give an example of a multiple-source assignment statement in Perl.
($first, $second, $third) = (20, 40, 60);
Provide an example of using the each statement in Ruby.
>> list = [2, 4, 6, 8] => [2, 4, 6, 8] >> list.each {|value| puts value} 2 4 6 8 => [2, 4, 6, 8]
True or False? In ML, elements of a list can be of different types.
False
True or False? Run-time descriptors of records are necessary.
False
True or false? Multiple exits from a control structure pose a danger.
False
True or false? Narrowing conversions are safe.
False
True or false? Unions in C and C++ are strongly typed?
False
True or false? In Java, floating point division by zero is an error.
False, infinity is a well defined value
True or False? In C#, implicit execution of more than one segment of a switch statement is allowed.
False, only 1
True or false? Java and C# allow mixed-mode assignments if the required coercion is either widening or narrowing.
False, only widening
True or false? Java and C# provide safe unions.
False, unions not included
True or False? In a Scheme list, elements are separated with a comma.
False- no punctuation
True or False? C based languages give OR a higher precedence than AND.
False. AND gets higher precedence than OR
True or false? In pure functional languages, content counters are used for iteration.
False. Do not contain counter variables and recursion is used instead of iteration
True or False? ML's tuples can be empty.
False. Must have at least 2 elements
What are the two ways to reference elements of a record?
Full Qualified Notation and Elliptical Reference
What are associative arrays called in Perl? Why?
Hashes, because elements stored/received with a hash function
In which programming language did list comprehensions first appear?
Haskell
When can a short-circuit expression cause an issue?
If a Boolean expression contains a side-effect, the side-effect may not occur
How does Java take care of the deallocation of heap-dynamic variables?
Implicitly using their garbage collector.
In Object Oriented Programming Languages, records are simulated with ________.
Objects
Name two other ways to implement a multiple selection statement.
binary search and hash table
In Ruby, a _____ is a sequence of code delimited by either braces or the do and end reserved words.
block
The ______ of a loop is the collection of statements whose execution is controlled by an iterative statement.
body
Java's while and do statements are like those of C and C++, except the control expression must have a ______ type.
boolean
Prior to C99, C had no _______ type. Instead, numbers were used.
boolean
What is the best implementation technique of a multiple-selection statement?
branch table (or jump table)
In a loop, what is an example of an unlabeled exit?
break
What is a narrowing conversion?
converts a value to a type that cannot store even approximations of all the values of the original type. i.e. int to byte
In Python, tuples can be deleted with the ____ statement.
del
What is a unary plus operator called? Why?
identity operator Since it usually has no effect
Python includes an _________ tuple type.
immutable
How do you access elements of a tuple in Python?
indexing
In a branch table, the ______ of the table are the case values.
indices
In most programming languages, binary operators are _______, appearing between their operands.
infix
How to prevent coercion in the relational expression In Ruby?
instead of using ==, use eql?
An ______ _______, or loop, causes a statement or collection of statement to be executed zero, one or more times.
iterative statement
In iteration based data structures, an iterative statement uses an _______ to traverse the elements of a data structure.
iterator
An operator can either have ______ or ______ associativity.
left or right
A counter controlled loop has a ______ ________ in which the count is stored.
loop variable
Name one operation in C used for heap allocation.
malloc
Most of the characteristics of arithmetic expressions in programming languages were inherited from ________.
mathematics
The problem of lost heap-dynamic variables is sometimes called ____ ______.
memory leakage
A _____-__________ statement allows the selection of one of any number of statements or statement groups.
multiple-selection
Describe the full qualified notation
must include all record names
How do you create a tuple in Python?
myTuple = (3, 5, 8, 'apple')
Type conversions are either _______ or ________ and can be explicit or implicit.
narrowing/widening
In Java, the else clause is always paired with the _______ previous unpaired then clause.
nearest
In Java, a value of a reference type is like a pointer, except that it must refer to an ______.
object
The ________ associated with a field specifies the distance from the beginning of the record to the beginning of the field.
offset
If pointers can point to variables that are not heap-dynamic, then there must be an _______ or _______ _________ that fetches the address of a variable.
operator or built-in subprogram
What is a mixed-mode conversion?
operators can have operands of different types
In programming languages, arithmetic expressions consist of what?
operators, operands, parentheses and function calls
Unary operators can be either ______ or _______.
pre/post fix
How can pretest logical loops be simulated in a functional language?
recursive function
A program has the property of ______ ______ if any two expressions with the same value can be substituted for each other without affecting the program's behavior.
referential transparency
A _______ ________ compares the values of its two operands.
relational operator
Assignments are ______ associative.
right
A ______ ________ provides a way of choosing between two or more execution paths in a program.
selection statement
List comprehensions are derived from _____ notation.
set
With _______ ________ _________, the value of an expression is determined without evaluating all its subexpressions.
short-circuit evaluation
What is an example of a multiple-selection statement in C#?
switch
What does the current function return in PHP?
the element that is currently being pointed to by the internal pointer
What is a side-effect?
the result when an operator or function call performs some other action in addition to returning a value i.e. int j = ++i + i; What is j? depends on the associativity
What are free unions?
the unions in C and C++ where there is no language support for type checking
Why are tuples used in Python, ML and F#?
to allow function to return multiple values
What's the ternary operator used for?
to form conditional expressions in C based languages
What are the two general paths that selection statements fall into?
two way and n-way
Elliptical references allow leaving out of record names if the reference is _________.
unambiguous
Write an example of a union in C.
union { int I; float f; }u; So you can write: float x; .... u.i = 27; x = u.f;
For a subprogram to use a pointer in C#, you must include the _____ modifier.
unsafe
Instead of a counting loop, Ruby has the _____ method.
upto i.e. >> 1.upto(5) {|x| print x, " "} 1 2 3 4 5
In ML, how are names bound to values?
using val (i.e. val cost = quantity * price;)
C and C++ allow pointers of type ______, which can point at values of any type.
void*
What is the return type of the function malloc?
void*
How to prevent a list from being treated as a function call?
with a quote i.e. (CAR ' (A B C) ) ....returns A
How can you access the first two elements of a tuple in F#?
with the functions fst and snd.
Name one area where pointers are beneficial.
writing device drivers
In C, ______ is considered false.
zero (all other values represent true)
The operator precedence rules of the common language are nearly all the same and include:
- 1. Exponents has the highest precedence - 2. Multiplication and division have lower precedence than 1 - 3. Addition and subtraction have lower precedence than 2.
If the pointer is pointing to an array, what are the 3 forms of pointer arithmetic supported in C and C++?
- Adding an integer to a pointer - Subtracting an integer from a pointer - Subtracting two pointers
What are the two operations that programming languages provide that have pointer types?
- Assignment - Dereferencing
What do the three expression in C's for loop represent?
- First expression: initialization - Second expression: loop control test - Third expression: Often used to increment loop counter since it's evaluated after each execution of the loop body
Name two ways that the following list can be interpreted as: (A B C)
- If interpreted as code, it's a call to the function A with parameters B and C - If interpreted as data, it's a list with 3 elements: A, B and C.
What were pointers designed to do?
- Indirect addressing - Accessing anonymous variables in the heap
What are the three parameters that the counter controlled loop also has?
- Initial value of the loop variable - Terminal value of the loop variable - Step size - the difference between sequential value of the loop variable
What are the two capabilities that most programming languages need?
- Select from among alternative control flow paths - Repeatedly execute sequence of statements
What are the three types of operators
- Unary: one operand - Binary: two operands - Ternary: three operands
What does a list comprehension do?
- applies a function to each element of a list and constructs a new list from the results. - i.e. in Python [x * x for x in range(12) if x % 3 == 0] produces [0, 9, 36, 81]
In C#, the last statement in each selectable segment ends with either a _____ or a _____.
- break - goto
How do you change a tuple in Python?
- by using the list function to convert it to a list - after the change use the tuple function to convert the list back to a tuple
To logically separate code segments in a switch, an _______ _______ much be used; C's _____ statement is an example and exits the switch statement
- explicit branch - break
Name the ML alternatives to CAR and CDR.
- hd (head) i.e. hd [5, 7, 9] is 5 - tl (tail) i.e. tl [5, 7, 9] is [7, 9]
What is the purpose of === operator in PHP?
- the "is identical to" operator prevents type coercion - i.e. "7" == 7 is true but "7" === 7 is false
Name two proposed solutions for the dangling pointer problem.
- the use of tombstones - the use of locks-and-keys
In F#, when an if construct has no else clause, the then clause must return a value of the ____ type. This type has only one value, which is written _________.
- unit - ()
What is a lost heap-dynamic variable?
A dynamic variable that is no longer accessible to a program
What is the locks-and-keys approach?
A pointer is stored as a (key, address) pair where the key is an integer value and each heap-dynamic variable has a header cell that store an integer lock value. When the heap-dynamic variable is allocated, a lock value is created and placed both in the lock cell of the heap-dynamic variable and in the key-cell of the pointer. When the pointer is dereferenced, the key value of the pointer is compared to the lock value of the heap-dynamic variable.
What are discriminant unions?
A union with a discriminant where each union includes a type indicator, knows as a tag or discriminant.
Which language has a single level of precedence?
APL
What is an associative array?
An unordered collection of data elements that are indexed by keys.
What's is Lua's only data structure?
Associative arrays
________ and ________ proved in 1966 that all algorithms could be expressed using only two control statements: one for choosing between two control flow paths and one for logically controlled iteration.
Bohm and Jacopini
What is the value of the relational expression normally?
Boolean
In Perl, subscripting is done using _______ and _______.
Braces and keys
In Scheme and Common Lisp, the ____ function returns the first element of a list.
CAR
In Scheme and Common Lisp, the _____ function returns the list minus its first element.
CDR . i.e. (CDR ' (A B C) ) returns (B C)
Records were introduced in what programming language?
COBOL
What is Scheme's multiple selector called?
COND
What happens when none of the predicates are true and there is no ELSE in Scheme's COND?
COND returns an unspecified value
_______ returns a new list with its first parameter as the first element and its second parameter as the remainder of that list.
CONS i.e. (CONS 'A '(B C)) returns (A B C)
In Java and C#, records can be defined as _______.
Classes
What does -> do?
Combines dereferencing and field reference.
What are reference types mainly used for?
Declaring parameters
What are associative arrays called in Python?
Dictionaries
In Perl, the ________ operator tests whether a value is a key in a hash.
Exists
_______ are the fundamental means of specifying computations in programming languages.
Expressions
How are fields of a record stored in memory?
In adjacent memory locations
In PHP, a subscript can be an ______ or a _______.
Integer or string
What is a dangling pointer?
It's a pointer that contains the address of a heap-dynamic variable that has been deallocated.
Is the following code valid in Ruby and does it produce the result displayed? >> 4.times {puts "Hey!"} Hey! Hey! Hey! Hey! => 4
It's valid and does produce the results displayed
Each element of an associative array is a pair consisting of a _______ and a _______.
Key and value
______ takes any number of parameters and returns a new list with the parameters as the elements.
LIST i.e. (LIST 'A 'B (C D)) returns (A B (C D))
______ ___________ are a powerful mechanism for creating lists.
List comprehensions
______ in Scheme and Common Lisp are enclosed in parentheses.
Lists
What was the first high-level programming language to include pointer variables?
PL/I
How do you override normal precedence and associativity rules?
Parenthesis
In Python, tuples can be catenated with the ______ _________.
Plus operator
_____ type values consist of memory addresses and the special value 'nil'
Pointer
What is a tombstone?
Pointer variables point to a tombstone cell that in turn points to the heap-dynamic variables.
What's the difference between a record and an array?
Record elements (fields) are referenced by name instead of indices.
What's the difference between Ruby's associative arrays and Perl's?
Ruby's keys can be objects. In Perl they can only be strings.
What does the assignment operation do?
Sets a pointer variable's value to some useful address
What does the continue statement do in a loop?
Skips the rest of the loop body
In ML, lists are specified in ______ ________, with the elements separated by ________.
Square brackets, commas
In Perl, each key is a _____ and each value is a _______.
String, scaler
In C, C++ and C#, records are supported with the _______ data type.
Struct
Lua's ______ can be used as records.
Tables
What does the reserved word rec indicate in F#'s function declaration?
That the function is recursive
What happens when an overloaded operator is used in an expression?
The compiler examines the types of operands to determine the correct meaning of the operator
Why are dangling pointers dangerous?
The location being point to may have been reallocated to some new heap-dynamic variable.
What is a difference between Python's dictionaries and Perl's hashes?
The values in Python are references to objects. In Perl they're scalars.
How are record fields accessed in memory?
Through offset
What is the best solution to the dangling pointer problem?
To provide implicit deallocation for heap-dynamic variables that are no longer useful
In Perl, how are elements removed from hashes?
Using delete
When does overflow occur?
When the result of an operation is too large to store in the designated amount of memory
When does underflow occur?
When the result of an operation is too small to represent.
How are new lists constructed in Scheme and Common Lisp?
With CONS and LIST functions.
How do you create a tuple in F#?
With the let statement. i.e. let tup = (3, 5, 7);;
How can tuples be defined in ML?
With the type declaration. i.e. type intReal = int * real;
Does PHP have associative arrays?
Yes
Name two ways to represent an empty list in ML.
[ ] or nil
What is a control structure?
a control statement and the collection of statements whose execution it controls
What is a record?
a data structure in which individual elements are identified by name
What is a tuple?
a data type that's like a record except that elements are not named.
If parentheses are omitted in control expressions, what is normally used?
a keyword marker such as then
What is a posttest loop?
a loop that tests the condition for loop completion after the loop body is executed.
What is a pretest loop?
a loop that tests the condition for loop completion before the loop body is executed.
What is a union?
a type whose variables can store different type values at different times during execution
Which language introduced compound assignment operators?
algol 68
What is a reference in C++?
alias for another variable
If pointers are used only to manage dynamic storage, the pointer variable is initialized by an ___ ___.
allocation mechanism
Describe elliptical references
allow leaving out of record names if the reference is unambiguous
Why does Java coerce byte variables into integers before an arithmetic operation is performed?
architecture. There's a way to add integers together, but not bytes.
How are cases matched in a branch table?
array subscripting
How are arithmetic and relational operators implemented in Ruby?
as methods since Ruby is a purely Object-Oriented language
When an expression contains adjacent occurrences of operators with the same precedence, __________ rules determine which operator is associated first.
associativity
Operator evaluation is governed by __________ and ___________ rules.
associativity and precedence
Why are lost heap-dynamic variables sometimes referred to as garbage?
because they're no longer useful, but the space they occupy cannot be reallocated
Why are casts placed in parentheses?
because type names may consist of more than one word: i.e. long double
How are unions implemented?
by assigning the same address to every possible variant
How does Python specify compound statements?
by using indentation
The ______ ______ _______ combines assignment with some other operation.
compound assignment operator (i.e. sum+=value)
What are the statements that provide the 2 capabilities called?
control statements
What is a widening conversion?
converts a value to a type that can include at least the approximations of all the values of the original type. i.e. int to double
Ruby's multiple-selection constructs are called _____ ________.
case expressions
What are explicit type conversions called?
casts
What are implicit type conversions called?
coercions
Accessing the memory cell a pointer points to is called ________ the pointer.
dereferencing
In a branch table, the _____ of the table are the segment values.
elements
In Ruby, the entire if construct is terminated by the word _____.
end
What is Java's solution to iteration over elements in an array?
enhanced for loop
What is another word for a run-time error?
exception
Languages that provide pointers for heap allocation must include an _____ ______ ________.
explicit allocation operation
Dereferencing can be either _____ or _______.
explicit or implicit
In most programming languages, dereferencing is done _______.
explicitly
How do you dereference a pointer in C++?
explicitly using the (*) as a prefix unary operation. i.e. j = *ptr
In C#, the iterator can be accessed through the _______ statement.
foreach
In Lisp, operators are _______.
functions
What's another term for lost-heap dynamic variables?
garbage
What is the unconditional branch statement called?
goto
If a pointer points to a structure in either C or C++, how can you access a field named age?
i.e. (*p).age or p->age