Prog Lang Final
What is the output of the following C++ code? int i[] = {3,6,9}; cout << (i+1);
0x7fefdfafdbbbb IE SOME HEXDECIMAL MEMORY ADDRESS
What is the output of the following C++ code? int i[] = {3,6,9}; cout << *&i;
0xblahblablah IE SOME HEXDECIMAL MEMORY ADDRESS
What are 2 solutions to functional side effect problem?
1- Write language definition to DISALLOW function side effects....no 2 way parameters in functions, and no non-local references in functions. 2- Write language definition to demand that operand evaluation order be fixed.
What is the output of the following C++ code? int i[] = {3,6,9}; cout << (*i)+1;
4
What is the output of the following C++ code? int i[] = {3,6,9}; cout << *i+1;
4
What is the output of the following C++ code? int i[] = {3,6,9}; cout << *(i+1);
6
Write the output of evaluating each of these Racket expressions, using correct Racket syntax. (+ 3 6) (/ 2 5) (/ 2 5.0) (* 2 (+ 1 7)) (= 3 2) (pair? '(1 2 3)) (or (and (= 3 (+ 1 2)) #t) #f) (car '(6 4 2)) (cdr '(1)) (cdr '(7 4 2)) (cons 5 7) (cons '(1 2) '(3 4)) (cons 3 (cons 6 (cons 9 '()))) ((λ (x y)(expt x y)) 2 3) ((λ (x) ((λ (y z) (z x y)) 2 /)) 1)
9 2/5 0.4 16 #f #t #t 6 '() '(4 2) '(5 . 7 ) '((1 2) 3 4) '(3 6 9) 8 1/2
Define static binding and dynamic binding.
A binding is static if it first occurs before run time and remains unchanged throughout the program execution. A binding is dynamic if it first occurs during execution or can change during execution of the program.
What is a block?
A block is a section of code that has its own local variables whose scope is minimized to that block
What is the potential danger of case-sensitive names?
A major disadvantage is readability. The names will look alike, but represent different variables, thereby causing confusion
Wrote the first software program
Ada Lovelace
What are the advantages and disadvantages of dynamic scoping?
Advantages: Variables do not need to be passed from one subprogram to another because they are implicitly visible in the called subprogram. Disadvantages: Accesses to nonlocal variables in dynamic-scoped languages take much longer than static scoped All variables are visible to any other subprogram, so there is no way to protect local variables from this. Less reliable programs. Inability to type check references to non-locals statically. Makes programs much more difficult to read because you need to know the calling sequence of the subprograms to determine the meaning of references to nonlocal variables. This can be impossible.
The binding of more than one variable to the same memory cell.
Aliasing
The process of taking a memory cell from a pool of available memory and binding it to a variable.
Allocation
What is an alias?
An alias is when two variable names are used to access the same memory location.
Although the + addition operator may be chained with multiple operands, it is actually a binary operator. Therefore, to evalute 2+3+5 we must first either (a) add 2+3 and combine the result with 5, or (b) add 3+5 and combine the result with 2. The property that describe which of these two strategies a language uses is called.
Associativity
Which of the following are categories of Dynamic Semantics? a. Proportional Semantics b Operational Semantics c. Compile time d. Axiomatic Semantics e. Syntactical Semantics f. Denotational Semantics
B - Operational D Axiomatic Semantics F Denotational Semantics
An explicit type conversion is called
Casting
Designed the first general purpose computing device, the "difference engine".
Charles Babbage
The process of placing a memory cell that has been unbound from a variable back into the pool of available memory.
DE-allocation
Variables that are nameless (abstract) memory cells allocated and deallocated by explicit run-time instructions written by the programmer.
Explicit heap-dynamic variables
Which languages do not support coercion in expressions?
F# and ML
In Java, String objects are mutable. T or F
FALSE
A Language is a collection of syntax rules that describe how to generate valid sentences. T or F
FALSE! A Grammar is.
Python data types are declared explicitly. t or f
False
An array in which the subscript ranges and the storage binding are both fixed after storage is allocated. Additionally, both the subscript ranges and storage bindings are done when the user program requests them during execution, and the storage is allocated from the heap.
Fixed heap-dynamic array
An array in which the subscript ranges are statically bound, but the allocation is done at declaration elaboration time during execution
Fixed stack-dynamic array
In Perl, and associative array is called a
Hash
An array in which the binding of subscript ranges and storage allocation is dynamic and can change any number of times during the array's lifetime.
Heap Dynamic Array
Variables bound to heap storage only when they are assigned values.
Implicit heap-dynamic variables
Designed the first widely-used high-level language (Fortran)
John Backus
Designed the hardware architecture used in most modern computers
John Von Neumann
A word of a programming language that is special only in certain Kontexts.
Keyword
Racket is a dialect of which older language?
LISP
At which possible binding time is the Java + operator symbol bound to a memory location?
Language Design Time
The time during which the variable is bound to a specific memory location.
Lifetime
At which possible binding time is a C or C++ static variable bound to a memory location?
Load Time
Dijkstra's selection structure looks like this: if <boolean expression> -> < statement > [] <boolean expression> -> < statement > ... [] <boolean expression> -> < statement > fi There are several _____ ____ in the structure, separated by the square brackets. The selection goes like this: if none of the boolean expressions evaluate to true, the program exits with an error. If one of the expressions evaluate to true, then the statement associated with that guard is executed. Finally, if more than one of the expressions are true, then one of the expressions is nondeterministically chosen, and the command associated with it is performed. WHAT IS THIS CALLED??
Loop Guarded Commands
Are the unions of Ada always type checked? Y or N
NO
Are tuples in Python mutable? Y or N
NO
A string of characters used to identify some entity in a program.
Name
Variables can be characterized as a sextuple of white six attributes? NAVTLS!
Name Address Value Type Lifetime Scope
What are the advantages of named constants?
Named constants are useful as aids to readability and program reliability. Readability can be improved by using the name PI instead of just a variable constant 3.1415. Named constants also parameterize the program. Constants also aid in modifiability, because only one constant needs to change instead of renaming many variables within a program.
What are the design issues for names?
Names can be case sensitive or insensitive. Special words can be reserved words or keywords. Depending on the language used, special characters may be allowed or required.
A _____ conversion is one that converts an object to a type that cannot include all of the values of the original type e.g., float to int
Narrowing conversion
_____ are used for addressing flexibility and to control dynamic storage management.
POINTERS
Which language below allows arrays to have negative integer indices? Perl, python, c++, java?
Perl and Python
The first high-level language, designed by Konrad Zuse.
Plankalkul
According to your textbook, what are the two distinct kinds of uses for pointers?
Pointers provide some of the power of indirect addressing. and Pointers provide a way to manage dynamic storage.
The ___ ___ _____ of most imperative languages include numeric, character, and Boolean types
Primitive data types
Select all that are examples of dynamic type binding.
Python x = int(4.0) and Perl $x = 4;
A special word of a programming language that can- not be used as a name.
Reserved Word
The first language designed specifically for text and string processing.
SNOBOL
Variables whose storage bindings are created when their declaration statements are elaborated, but whose types are statically bound.
Stack-Dynamic Variables
An array in which both the subscript ranges and the storage allocation are dynamically bound at elaboration time.
Stack-Dynamic array
An array in which the subscript ranges are statically bound and storage allocation is static (done before run time). IF IT SAYS STATICALLY AND STATIC, the ANSWER IS STATIC ARRAY!
Static Array
Variables that are bound to memory cells before program execution begins and remain bound to those same memory cells until program execution terminates.
Static Variables
There are three reasons why lexical analysis is separated from syntax analysis: Simplicity, Efficiency, Portability. T or F
TRUE
Define lifetime, scope, static scope, and dynamic scope.
The lifetime of a variable is the time during which it is bound to a particular memory cell. The scope of a variable is the range of statements over which it is visible. Static scope is named that because the scope of a variable can be statically determined - that is, prior to execution. Dynamic scope is based on the calling sequence of subprograms, not on their spatial relationship to each other. Thus, the scope can be determined only at run time
What is a static ancestor of a subprogram? What is a dynamic ancestor of a subprogram?
The static ancestors of subprogram refer to the nested subprograms that make up an application. For example, if we are searching for a variable and it does not exist in a given block, then we will continue the search to the next-larger enclosing unit, which is known as the static parent. If we still have not found it, we would again search the next-larger enclosing unit, which is known as the static ancestor. This process continues until we either locate the variable, or return an error. The static ancestors are strictly those that contain the subprogram in question. Dynamic ancestors are any functions that are called to reach the subprogram in question. They have not finished executing, as they are waiting for the subprogram to complete.
A tuple is a data type that is similar to a record, except that the elements are not named. T or F
True
A programming language is strongly typed if
Type errors are always checked
An abstraction of a computer memory cell or collection of cells.
Variable
Are the unions of F# discriminated? Y or N
YES
Which of the following is NOT a characteristic of language evalutation criteria associated with Writability? a. Exception handling b. Syntax design c. Simplicity d. Data types
a Exception Handling is NOT a characteristic of Writability.
The Readability of a program is affected by which characteristics? (check all that apply) a. Syntax design b. Simplicity c. Restricted aliasing d. Type checking
a. Syntax Design b. Simplicity
An associative array is an unordered collection of data elements that are indexed by
an equal number of values called keys, which may be strings or numerics.
_____ and _____ are included in most languages
arrays and records
The values of enumeration constants
can be explicitly assigned ANY integer literal in the type's definition.
The ____ ______ of a language are a large part of what determines that language's style and usefulness
data types
What are some of the features of Functional Programming Languages? (select all that apply) a. Support for dynamic variables b. Data abstraction c. Close semantic parallels with assembly language d. Based on first-order logic (FOL) e. Ability to return a function as a valid return type of a function f. The presence of anonymous (unnamed) functions g. Ability to pass functions as arguments to other functions h. Elimination (or minimization) of side effects
e. Ability to return a function as a valid return type of a function f. The presence of anonymous (unnamed) functions g. Ability to pass functions as arguments to other functions h. Elimination (or minimization) of side effects
The user-defined ____ and _____ types are convenient and add to the readability and reliability of programs
enumeration and subrange
In programming languages, the use of KEYWORDS is MORE restrictive than RESERVED WORDS. true or false
false
Life the 'if/else' statement in Java and C++, the Racket else statement is optional. t or f
false
Two Way selection statements are generally called
if/else statements. But you can also use if/else/elseif to create multiple selection statements, not just two way.
Which of the following are signed integers in Java?
int long short byte
What is the word for 'use of operator for more than one purpose'?
operator overloading
Multiple way selection statements are generally called
switch statements
Choice of control statements beyond selection and logical pretest loops is a
trade-off between language size and writability
A programming language is strongly typed if
type errors are always detected.
Old school goto statement style-- called ____________ branching.
unconditional
A union is a data type whose variables
whose variables may store different type values at different times during program execution.
A __________ conversion is one in which an object is converted to a type that can include at least approximations to all of the values of the original type, e.g., int to float
widening