Exam questions Flashcards

1
Q

2 reasons why studying programming languages can also be useful for legacy development projects

A

1: It can help you understand low level bugs
2: To better understand different coding paradigms

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

Why is C good for systems programming?

A

1: efficient
2: Very flexible/powerful

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

Give an example in which cost of compiling is a concern.

A

When writing programs that should still be able to run on older devices or with devices with weak cpu’s

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

. Describe main tradeoff between language evaluation criteria, which is illustrated by APL:

A

reliability vs writability
readability vs readability
reliability vs cost of execution

APL = writeability vs readability
it is very writeable/expressive but it makes it difficult to read

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

Pure interpreted languages are slower than compiled languages. why?

A

Translation happens at run time.
More storage is needed to check referencing environments and scoping

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

Comment on the orthogonality of functional programming languages

A

It is very orthogonal since there arent really data types to define but rather implicit variables usually

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

What was the 1st high-level programming language?

A

Zuse’s plankalkul

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

What was the first true OOP language?

A

smalltalk

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

First language based on formal logic inferencing process, used to answer queries

A

prolog

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

What effect does target users have on COBOL

A

It is more business oriented since it was made to be a business language.

Business people also needed it to be easy to understand and close to english

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

PL/I vs Algol 68. Which has superior approach to supporting general purpose data structures?

A

PL/I

Focused more on practicality and usability

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

How is Pascal and C++ similar

A

Structured programming. Static typeing
Influancial

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

i = 12

Explain difference between implicit declaration and dynamic type binding.

A

With dynamic type binding, the type of i would be able to change after the initial assignment, but with implicit declaration the type of i cant change whenever it wants

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

What effect does keywords instead of reserved words have of readability?

A

Keywords name actions thus it would increase the readability

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

int arr = new int[50]

What category is arr in terms of variable lifetime?

what is the advantage of this type over static

A

heap-dynamic

flexibility + life time control

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

fun1 {
var x
var y
call fun3
fun2 {
print x “ “ y
}
fun3 {
var x
call fun2
}
}

reference environment if statically scoped vs dynamically scoped

A

static = fun 1

dynamic = fun 3

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

3 characteristics of a variable that the type of the variable determines

A

How it is stored.
What values it can hold
Set of operations that can be performed on it

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

What is the advantage of decimal data types?

A

Accuracy

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

What is the disadvantage of decimal data types?

A

Range

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

What is the impliation if enueration types can be coerced to integer values?

A

weak type safety

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

Why is heterogeneous array operations less efficient than homogeneous?

A

Because a hetro can store different types of elements while a homogeneous only stores one type. SO the operation has to be defined for all type in hetro arrays

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

Why can pointers be bad for readability in comparison to references

A

Constantly need to dereference the pointers.
Assignment for pointers is also worse that for reference variables

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

When must a value from memory always be performed for a constant value?

A

When the constant is defined externally, in a different scope, or if it is a complex data structure

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

3 reasons why C is not referentially transparent:

A

1: Side effect
2: Mutable data
3: Input out operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
integer myInteger = 20; float myFloat = 2.8; print(myInteger + myFloat); What is problem could arise? And how does Ada solve this
If coercion isnt allowed, then it would give a run time error. Aka type mismatch Ada is a strongly typed language with strong type safety.
26
in a functional programming language val result = 12; how does this differ from a imperative language? What happens if you run val result = 4 after the previous one?
With an imperative language you would have to specify the type of the result Depending on the language implementation, it will either throw an error or simply assign the new value of 4 to result
27
if (i < 10) if (j > 2) print "output 1" else print "output 2" Problem with semantics? how does python solve it? how does Ruby solve it?
To which if does the else belong? It uses indentation With special words to mark the end of the if
28
Briefly explain a problem related to the readability and writability of multiple-way selection statements in C++. How is C# safer?
It needs break statements otherwise it might include execution for subsequent cases C# is safer because you cant execute more than one consecutive segment needs a break in each case
29
Consider counter-controlled loops in C++ and Ada. Contrast the flexibility of the counter-controlled loop support in these two languages. It is recommended that you use a bulleted list to separate your points.
C++ = more flexible Ada is more safe and readable Ada also has implicit control variable and C++ explicit
30
Write pseudocode to illustrate how a while loop can be simulated in a functional programming language. [4] Use the following function header as a base, where whileLoop is the name of the function defining the loop, and the loop has two parameters, test and body. The test parameter is function defining the logical test upon which the loop is based, while the body parameter is a function defining the body of the loop. Note that the syntax you use is not important, but the logic of your pseudocode must be correct. whileLoop test body
whileLoop(test,body) if (test) body() whileLoop test body end if end func
31
Consider the following guarded command: [1] if boolean_expression_1 -> statement_1 [] boolean_expression_2 -> statement_2 fi Explain what the result is if both the Boolean expressions are true.
It could be either. Execution order does matter
32
List two ways in which subprograms can have side effects.
Changing a global variable or a function parameter
33
Name the type of subprogram that does not produce side effects.
Functions
34
Name the type of abstraction that subprograms promote.
Process abstraction
35
In Python, subprogram definitions are said to be executable. Explain what this concept entails. You may use a code snippet to illustrate your point, if this will make your explanation easier.
When you call the function directly it can execute
36
Briefly describe a disadvantage associated with positional subprogram parameters
If you switch around 2 parameters accidently it could still execute but the output would be "wrong" in the sense that it wasnt what was expected
37
In C++, default parameters must appear last in the list of formal parameters for a subprogram. Suggest one [1] way in which a programming language can allow default parameters to appear anywhere in the parameter list.
By using named parameters
38
Contrast the approaches used by C++ and Java, when providing support for generic subprograms.
Finish this question
39
Explain how studying the concepts of programming languages can lead to overall advancement of computing?
By studying concepts a developer would gather more insight to the tools available to him and therefore be able to choose a better tool for a project. It also helps understand the strengths and weaknesses of the different languages and also the environment they were built for
40
Programming languages are applied within 1+ programming domains. List 2 important requirements of a programming language that is to be used in the domain of scientific programming
It must be able to write mathematical functions and be close to english to understand
41
What is orthogonality in programming languages? Consider two hypothetical programming languages. Language A supports the multiplication of two integer operands using one operator, and the multiplication of two floating point operands using another operator. Language B supports multiplication of two operands using only one operator, where either operand may be an integer or a floating point value. Compare the orthogonality of the two languages, and explain your answer.
The ability to perform different type calculations without having to have a specific operand for the 2 operations. It is the language's ability to "mix and match" operations on different data types and it still being valid Language A is less orthogonal than B since B can use 1 operand for 2 different data types
42
What are the various factors that affect the cost of a programming language?
Cost to train programmers Cost of compiling Reliability
43
COBOL programs contain two divisions: the procedure division and the data division. Identify which one of these divisions is better developed. Explain why this is the case, taking into consideration the programming domain that COBOL is intended for
Data division. Since it was designed for business applications where data accuracy and integrity are paramount
44
Compare the general approaches that Fortran and COBOL use in terms of syntax.
Fortran is more mathematically focused while COBOL is business focused. Therefore COBOL is generally described as being more readable
45
Describe the most important programming language feature or paradigm that each of the following languages introduced: (a) Prolog. (b) SIMULA 67. (c) LISP. (d) Smalltalk. (e) ALGOL 68.
A) Logic programming B) OOP C) List processing for AI development D) Pure OOP principles E) Orthogonality
46
Compare APL and COBOL in terms of readability and writability
COBOL was better both in terms of readability and writability since APL was too complex and too difficult to read and therefore also very difficult to write even though APL was very expressive
47
Consider the C programming language, and answer the following questions: (a) Name the programming domain within which C was originally intended to be used. (b) Explain why C is considered to be a relatively unreliable language, taking into consideration your answer to (a), above.
A) For system programming B) Because of input and output which could lead to different results thus decreasing reliability
48
Critique the use of case sensitivity in names (i.e. identifiers) within a programming language, both in terms of readability and writability.
Bad for readability: Because numberOne and numberone would look the same but be totally different variables making it hard to read exactly what is going on Bad for writability: Because the programmer would have to remember the exact case for each letter in for example OutOfIndexErrorArray
49
Name the two (2) things that are determined by a variable’s type.
How it is stored and what operations can happen with it
50
Consider the concept of keywords and reserved words in programming languages, and answer the following questions: (a) Explain what a keyword is, as opposed to a reserved word. (b) Explain how reserved words can adversely affect the writability of a programming language.
a) A keyword names a action and is a subcategory of a reserved word b) Can decrease writability since there could be more collisions and then the programmer would have to figure out new ways to name the variables he wants to name
51
Name one (1) advantage associated with variables that have static storage binding.
Efficiency
52
Consider the following statements in a hypothetical programming language: var myValue; myValue = 12; myValue = [4, 3, 2, 1]; Answer the questions that follow: (a) Identify the type binding that is taking place in the above program code. (b) Identify the storage binding that is taking place in the above program code
A) dynamic implicit type binding b) stack dynamic
53
Consider the following set of subprograms in a hypothetical programming language: int var1; Main { int var2; call Sub1; } Sub1 { int var3; <--- (A) } Write down the referencing environment at point (A) in the program, for each of the following cases: (a) If the hypothetical language uses static scoping rules. (b) If the hypothetical language uses dynamic scoping rules
A) It is using the referencing environment of when it was "compiled" so it will have the referencing environment outside of both function and the one inside Sub1 B) It will have the referencing environment of when it was called so in this case All of the environments
54
Consider floating point and decimal data types, and answer the following questions: (a) Name one (1) disadvantage associated with floating point data types. (b) Name one (1) disadvantage associated with decimal data types.
A) Rounding errors b) Limited range
55
The inclusion of a separate Boolean value is not a requirement within a programming language. Explain how a programming language might be able to do without a separate Boolean type.
You can use values to simulate such boolean values with true being 1 and false being 0. Or with words but that could complicate things a bit
56
Consider the concept of a string type, and answer the following questions: (a) Contrast the methods used by C and C# to represent strings. (b) Name one (1) disadvantage associated with dynamic length strings.
A) C uses character arrays to represent the strings B) Extra overhead when performing operations with the strings
57
Consider the following program code snippet in a hypothetical programming language: void function() { int size = 10; int myArray[size]; } Identify the type of array, in terms of its subscript and storage binding
Subscript = static. Storage = stack dynamic
58
Describe the basic difference between normal arrays, and associative arrays.
A normal array only has a index for where to element is stored while a associative array associates one thing with the other. An example of a associative array is a hash map. A associative array has key value pairs
59
What is a elliptical reference
An elliptical reference is when you omit intermediate names in the reference path of a record
60
Main difference between pointers and references?
References gives a direct access path to the storage location of the variable
61
Differentiate between operator precedence rules, and operator associativity rules
Operator precedence is what operator gets "executed" first while operator associativity rules which is evaluated first if they have the same level of precedence
62
Describe how Ruby implements operators
It is implemented as methods hence you can overload it
63
Describe two (2) different ways in which a functional side effect can occur.
Modifying a function parameter or a global variable
64
Describe one (1) problem that can occur when the programming language itself (i.e. not the user of [1] the programming language) overloads operators.
It could result in the incorrect overloaded "version" of the operator to be used resulting in incorrect execution
65
Describe one (1) problem that can occur when the user of a programming language (i.e. not the [1] programming language itself) overloads operators.
It can lead to ambiguity
66
Explain Ada’s approach to type conversions in expressions and assignment statements
It is explicit using the () notation f :=Float(i) Type on the right must be identical or convertible
67
Contrast the representation of Boolean values in early versions of C (i.e. C89) and Java.
C had no explicit boolean type but rather integers while java has a dedicated boolean type
68
Give an example of a situation in which the lack of short-circuit operators can cause a problem in a user’s program code. You may simply describe the situation, but it will probably be easier to provide program code or pseudocode. If you provide code, your exact syntax will not be marked, as only the basic structure of your example is important. Make sure that your answer is clear enough to understand, and add notes for clarity, if you need to.
if( node != null || node.value == 5){ node.value = 6;} if there is no short circuit it could still try to access the.value of the node which is null
69
Explain what two (2) language features must be present in a language if a control statement has multiple entry points.
It must have labels and goto's
70
Consider the following pseudocode program example, and answer the following questions: if (condition1) if (condition2) statement1 else statement2 (a) Describe a problem that arises when evaluating these statements. (b) Explain how Java addresses the above-mentioned problem. (c) Explain how Python addresses the above-mentioned problem.
a) to which if does the else belong b) with {} c) with indentation
71
Consider the concept of multiple-way selection statements. Explain how C# ensures more reliable multiple-way selection statements than C++ does.
with switch case statements, each block in c# needs a break at the end of it while with C++ you can execute multiple blocks that follow the initial block
72
Contrast how C++ and Ada determine the number of iterations that a counter-controlled loop will execute
Ada has a explicit range with auto counter management while C++ uses a more user type counter management
73
Contrast the support for unconditional branching in C and Java.
Since C was used for systems programming it has much more support for conditional branching than java with goto statements
74
Explain what happens when more than one expression evaluates to true in the following example of Dijkstra’s guarded selection statement: if -> [ ] -> fi
It will execute the statement of which ever was tested first. It happens in a non deterministic way such that the order doesnt matter
75
Differentiate between formal parameters and actual parameters.
Formal parameters is like (int a, int b) while actual parameters are the actual values that are being passed in.
76
Consider the concept of keyword parameters, and answer the following questions: (a) Describe one advantage of keyword parameters. (b) Describe one drawback to keyword parameters.
A) you cant mix up the parameters. b) It decreases writability
77
Differentiate between how functions and procedures deal with their results.
Precedures produce result by modification. Whether its parameter or global variables while functions return the values to the variables they were assigned to
78
Describe one (1) disadvantage associated with pass-by-value parameters.
Extra storage needed to copy the actual parameter to the formal parameter
79
Consider the following pseudocode example of a subprogram definition: sub(integer reference a, integer reference b) { ... } Also consider the following call to this subprogram: call sub(c, c) Answer the following questions: (a) Describe the main problem that is associated with this specific example, and under what circumstances this problem occurs. (b) Suggest a possible solution to this problem.
a) it can produce side effects and unpredictable behaviour. This happens when a or b is modified b) Dont allow pass by reference
80
Contrast how C++ and C# handle array dimensions when arrays are passed to subprograms
In C++, arrays decay into pointers when passed to functions, requiring manual size handling, while C# arrays inherently maintain their size information, simplifying array operations within functions.
81
List the two (2) fundamental requirements that any abstract data type (ADT) must satisfy
1: Abstraction ( hiding internal representation) 2: encapsulation. Dont allow unauthorized access or modification
82
Explain what a property is in C#.
A way of implementing getters and setters without explicit calls
83
Classes in Ruby are dynamic. Explain what this concept entails
You can add or remove attributes or properties from it when executing
84
Consider the concept of parameterized classes. Contrast how C++ and Java handle parameterized classes.
C++ uses templates and Java uses generics. C++ is more flexible and instantiates at compile time
85
General encapsulation constructs (note: this question does not refer to naming encapsulations) are in-tended to support separate compilation. Explain how C supports separate compilation via encapsulation constructs
It uses header and source files
86
Explain what the purpose of naming encapsulations is (note: this question does not refer to general encapsulations for separate compilation).
It prevents naming conflicts (aka using namespace)
87
One of the reasons for studying programming language concepts is to gain a better understanding of the significance of implementation. Describe one (1) reason that such an understanding could prove to be practically useful.
Understanding the significance of implementation helps because it gives us a better idea of how the language works and how we can get the most out of it
88
Define the concept of orthogonality
the ability to combine different language constructs and features in a consistent and predictable manner, without unexpected side effects or limitations.
89
Consider two hypothetical programming languages, A and B. Both programming languages support several primitive data types and a record data type. In both languages, record fields may be of any type (including both primitive and record types). Programming language A allows a record R to contain a field whose type is itself R. Programming language B considers such nested composition to be an error. (a) Define the concept of orthogonality in a programming language. [1] (b) Compare the orthogonality of these two languages, and explain your answer.
A) the ability to combine different language constructs and features in a consistent and predictable manner, without unexpected side effects or limitations. B) Language A is more orthogonal than language B since it allows more constructs. Hence it will be more predictable
90
1 reason why pure interpretation is slower than compilation
It needs to translate the code to machine code as the program is running
91
Name the type of application area that COBOL was designed for
Business applications
92
Pseudocodes (e.g. Short Code and Speedcoding) were purely interpreted. Only later did high-level languages begin using the standard compilation process that is commonly used today. Explain why this was the case
There are multiple factors that attribute to this. Firstly, there wasnt a previous design language that used compilation so the majority just followed the norm. It is also much easier to implement an interpreter rather than a compiler. And lastly, programs werent complex enough or big enough to need compilation and pure interpretation would suffice
93
Consider each of the following languages. For each, briefly explain the single most important programming language concept introduced by the language: (a) SIMULA 67 [1] (b) LISP [1] (c) Smalltalk
A) OOP B) Recursion C) Pure OOP programming
94
Contrast the approaches that were used by PL/I and ALGOL 68 when providing support for a wide variety of end-user data structure needs.
PL/I was designed for scientists and business applications and ALGOL was more focused on orthogonality
95
Name the programming language paradigm (category of programming language) that Prolog falls within.
Logic
96
In a programming language, special words may be either keywords or reserved words. Differentiate between keywords and reserved words in a programming language context.
Keywords are a subset of reserved words specifically used for naming actions that take place
97
Consider the following program code snippet from a hypothetical programming language: myVariable = 12; myVariable = "Test"; Answer the questions that follow, in context of this programming language: (a) Name the category of type binding that this language uses for its variables. (b) Name the category of storage binding that this language uses for its variables
A) Dynamic B) stack-dynamic
98
Give an example of a situation in which the scope and lifetime of a variable are not related to one another. Make sure to explain what the scope and lifetime are for the type of variable that you describe.
Pointers When a pointer is declared inside of a function, its scope remains within that functions but its lifetime remains until either the end of the program or until it is deleted
99
Consider the following code snippet from a hypothetical programming language (note that this language allows nested subprograms): main() { var X; func1() { var X; <-------- (A) } func2() { var Y; call func1(); } call func2(); } For each of the following types of scope, write down the referencing environment (including the subprogram scope of all variables in the referencing environment) at the point marked (A) in the code: (a) Static scoping. [3] (b) Dynamic scoping.
A) Func 1 will have X from main. and nothing else B) Func 1 will have X from func 1, Var y from Func2
100
Consider floating point and decimal data type representations of real numbers. Answer the following questions: (a) Explain the difference between the low-level representations of floating point and decimal data types. (b) Name one (1) advantage that floating point data types have over decimal data types
A) Floating point is stored using bits to represent different parts of the number. Decimal is also stored like floating point but doesnt have an exponent that it stores B) Range
101
Consider the concept of an array data type, and answer the following questions: (a) Explain the underlying representation that a programming language must use for multidimensional arrays, in order to make jagged arrays possible. (b) Explain how associative arrays differ from normal arrays.
A) It most store all the dimensions for each row and column/ pointers? Isnt in the book B) Normal arrays uses indexes in order to access elements while associative arrays normally uses key that is linked to a value
102
Explain the difference between elliptical references and fully qualified references in terms of the following [2] hypothetical example of a record: record BankAccount { record AccountHolder { string firstName; string lastName; } real balance; }
A eliptical reference would be just using balance instead of BankAccount.balance while a fully qualified reference would be BankAccount.AccountHolder.firstName
103
Consider the union data type, and answer the following questions: (a) Explain what a union data type is. [1] (b) Name the type of union that is generally considered to be unsafe.
A union is a data type that can be a different type at different times during execution B) A free union
104
Explain by means of an example how a dangling pointer can occur in a language that supports pointers.
A dangling pointer is a pointer that referes to a memory location that has been deallocated or no longer valid. This makes it such that there can be a potential crash
105
Explain why references are generally considered a safer means of indirect addressing than pointers.
Because you cant have memory leaks or dangling pointers with references.
106
Programming languages that allow many coercions tend to reduce their ability to type check. Explain how Ada addresses this problem.
Ada uses strong typing and limits implicit coercion Ada uses strong typing and limits implicit coercion
107
Consider the following program code snippet from an implementation in a hypothetical programming language (where the <> operator denotes the “not equal to” equality test): if ((a <> 0) AND ((b / a) == 1)) print("Test successful"); The code snippet contains a potentially serious problem. Name a language feature that can be used to avoid this problem, and explain how it avoids the problem.
It not certain if the print should execute even if the if statement fails. Use indentation or brackets to indicate where the print statement belongs
108
Consider the following expression in a hypothetical programming language: a + fun(a); Answer the questions that follow: (a) Explain how a function side effect and the operand evaluation order can interact to make the final value of the expression ambiguous. (b) Suggest one (1) solution to the above-mentioned problem of function side effects.
A) If the order is from left to right the function would perform as "expected" but if its from right to left then fun could change a and thus would flow over to the stand alone a variable and thus be unpredicatble B) Dont allow functions to change the values of parameters or global variables