CSE - 240 (ASU): Introduction to Programming Languages
1. A programming language can belong to multiple paradigms (T/F)
- True
 
2. Features of the imperative or procedural paradigm includes
- Manipulation of named data(variables) and conditional statements
 
3. (T/F) Logic programming languages divide the program into reasonable sized pieces named functions or procedures or modules or subroutines
- False
 
4. Direct execution of one statement at a time sequentially
- Interpretation
 
5. simpler semantics and computation expressions in terms of mathematical function are features of which paradigm?
- Functional
 
6. Expressing computation in terms of logic predicates is a feature of which paradigm?
- Logic
 
7. Inheritance, classes & objects are features of which paradigm
- Object Oriented
 
8. A set of principles, concepts and methods that is commonly accepted by members of a group or community
- Programming Paradigm
 
9. (T/F) Prolog is a functional programming language?
- False
 
10. (T/F) the compiler executes the program
- False
 
11. The semantic structure of imperative programming languages normally include which of the following validations
- type matching, parameters type in a function declaration should match these in the function call, unicity
 
12. (T/F) Functional programming languages are low-level languages
- False
 
13. (T/F) compilation of a program is to execute all the statements of the program completely
- False
 
14. They syntactic structure of imperative programming languages normally include which of the following units?
A. Operators
B. keywords
C. identifiers
15. What programming language uses two-step translation with intermediate codes for execution?
- JAVA
 
16. (T/F) Interpretation of a program is the direct execution of one statement at a time sequentially.
- True
 
17. (T/F) during compilation, all statements of a program in a high-level language are converted to a low-level language.
- True
 
18. A set of primary values and the operations defined on these values
- data type
 
19. The lexical structure of all programming languages are similar and include which of the following units?
B. Loop statements
F. variable declaration
20. What does the follow code print?
int foo(int *n) {
*n = 30;
}int main() {
int i=15;
foo(&i);
printf("i=%d\n",i);
i=10;
foo(&i);
printf("i=%d\n",i);
return 0;}i = 30
i = 30
21. What does this program print on the screen?
#include <stdio.h>
int main() {
int i=3, *j, k;
j=&i;
printf("%d\n",i*ji-*j);
return 0;
}- 24
 
22. A classification that specifies which type of value a variable has and what type of mathematical, logical or rational operations can be applied to it
- Data type
 
23. A name given to a storage location
- Variable
 
24. Fixed value that the program may not alter during its execution
- Constant
 
25. A name given to a storage location that stores an address
- Pointer
 
26. In a C program, how many parameters are allowed for main
- C allows empty parameters or two parameters for main
 
27. The following code prints "hello" (T/F)
if (2+2+2)
printf("hello")- True
 
28. Primitive data types in C
- float, double, char, int, void
 
29. These data types are NOT primitive in C
- bool, short, String, long
 
30. what is the output of the following code:
#include <stdio.h>
int main() {
int a[5]={3,1,5,20,25};
int i,j,m;
i=*(a+1) - 1;
j=a[1] + 1;
m=a[j] + a[i];
printf("%d,%d,%d",i,j,m);
return 0;
}- 0, 2, 8
 
31. char, unsigned char, signed char and int are all numeric (integer) types in C (T/F)
- True
 
32. in C, when you pass an array as a parameter to a function, what is actually passed?
- The address of the first element in the array
 
33. control symbol %d is used for
- printing format for integer values
 
34. control symbol %f is used for
- printing formation for floating point values
 
35. control symbol %c is used for
- printing format for characters
 
36. control symbol %s is used for
- printing format for strings of characters
 
37. control symbol %p is used for
- printing format for memory address (pointer stored values)
 
38. (T/F) The scope resolution operator (::) is used to overload a function or an operator in OO paradigm
- False
 
39. What is the equivalent C++ code to this code in JAVA:
int x = 5;
char a = 'A';
System.out.print("hello" + x + "," + a);int x = 5;
char a = 'A';
cout<<"hello"<<x<<","<<a;
40. What declaration allows all elements in the standard C++ library to be accessed in an unqualified manner (without std::prefix)
- using namespace std;
 
41. initialize a static variable 'v' of class Something in C++
- int Something::v=1;
 
42. (T/F) in C++, implementations of member functions cannot be inside the class definition (for short functions) or outside of the class definition
- False
 
43. The principle behind the object-oriented paradigm consists of a number of programming concepts, which does not include:
- Pointers and Arrays
 
44. Translates in runtime and executes each statement in the high level language
- Interpreter
 
45. makes the language and the compiler machine-independent
- Intermediate code
 
46. (T/F) A program in C must contain at least one main
- True
 
47. (T/F) C allows void or int as type for main
- True
 
48. (T/F) In C, if there is not a type, C applies type as default int
- True
 
49. C++ primitive data types include
- float, double, char, int, void and bool
 
50. primitive data types can be modified using one or more of these modifers
- signed, unsigned, short, long
 
51. Homogeneous collection of data elements
- arrays
 
52. (T/F) In C, there is not a class String like in Java or a primitive type String
- True
 
53. Two ways to initialize an array in C
- char s1[]={'a','l','p','h','a'};//as an array of char, size:5
 - char s2[]="alpha";//as a string, size: 6
 
54. What are the two pointer operators for C
- &, *
 
55. Introduces a new name that becomes a synonym for the type given
- TYPEDEF: typedef typename(int) newname(boooOlean)
 
56. Allows us to define the allowed values for a new type
- enumeration (integer constants) labels that represent an integer value
 
57. composite data type declaration that defines a physically grouped list of variables to be placed under one name in a block of memory
- structure(similar to a java class; but DOES NOT allow methods)
 
58. In scheme, the form(symbol-length? 'James) will return:
b. 5
c. 0
d. 7
e. 6
59. Functional programming languages do NOT allow us to define
a. procedures
b. multiple parameters in one procedure
c. variables whose value can be modified
d. named values
60. convert the following expression into prefix-p notation
-5 * (2 + 1/2) + 40b.(-5 *(2+1/2)+40)
c. (* (+(-5)(/2 (+1 2)))40)
d.+*-5+2/1 2 40
61. convert following exp into pre-fix p
10 + (5-3) + 2 / 4a. + 10 - 5 3 / 2 4
b. (/ (+ 10(- 5 3)2)4)
d. 10 + (5-3) + 2/4
62. which of the following is a valid scheme expression?
a. 9 *(4 -2)/7
b. *9(/(- 4 2)7)
d. *9 / -4 2 7
63. one of the major difference between imperative and functional programming languages is that the functional programming languages do NOT
a. support call-by-calue parameter passing
b. allow nested function calls
c. allow a procedure to return a value
64. the statement "a function is a first-class object" means that a function
a. must have a return value
b. must be instantiated from a class
c. can be placed in a place where a value is expected
d. may not have side effects
65. given this procedure, what is the return result?
(define (guess value)
(cond ((number? value)"I'm a number")
((char?value)"I'm a characted")
((interger?value)"I'm a integer")))(guess 10)
a. "i'm a character"
b. error
c. "I'm a integer"
66. the scheme form(char? #\5) will return
a. error
b. true (#t)
c. false (#f)
d. 5
67. a student is wondering if scheme is a strong or weakly typed language. how might they check this?
a. they could execute a form like (+ 10 10) in the REPL. if it works (like in C), then it is probably weakly typed
c.they would need a five-eyed alien or wizard to check the source code of the language for them
d. they would have no choice but to ask the instructor
68. what is the expected result for this expression?
(string-ref "Hello World" 4)
a. #\o
b. #\space
c. #t
d. #\l
69. Given an expression: x1 + x2 + x3 + x4
Which language allows to evaluate the expression in this order: (1) x1 plus x2; (2) x3 plus x4; (3) sum of ( x1 + x2 ) plus sum of ( x3 + x4 ), without concern for producing a difference result than other evaluation orders:
a. C/C++
b. all of the above languages
c. java
d. scheme
70. which of the following are typical advantages of using a REPL for software development?
a. they let you save your program into a project that stored into a solution
c. they let you compile a program into a static executable that is very efficient
d. they let you experiment with small pieces of code to understand how they work
71. how would scheme implement a function such as: for(i=1;i<100,i++){sum=sum+i;}
b. with a for-loop
c. with a while-loop
d. with a repeat-until loop
72. the display form (display "Hello") violated the functional paradigm because it
a. can output text only
b. is an invalid form
c. outputs a result
d. does not have a return value
73. a let-form in scheme is equivalent(in giving names to values) to
a. an unnamed/lambda procedure
b. a global name
c. a tail-recursive procedure
d. a stateless procedure
74. a let-form in scheme defines a set of
a. variables
c. global names
d. primitives
75. what functional feature does the code below best exhibit
(define start-engine (lambda()
(error-detection(wheel-velocity(wheel-sensor))(body-velocity))))a. use local variables to store intermediate values
b. procedures are first class objects
c. use recursion instead of loop
d. sequential processing of componenets
76. Given the scheme code, answer the following two questions.
((lambda(x)
((lambda (x y)
(+ x y))
5(* 7 x)))
3)(1) the value to be passed to the param y is ?
(2) the final output to the piece of code is ?
Answer
(1) 21
(2) 26
77. Given the scheme code, answer the following questions.
((lambda(x)
((lambda(x y)
(+ x y))
4(* 6 x)))
3)(1) the value to be passed to the parameter y is ?
(2) the final output to the piece of code is ?
Answer
(1) 18
(2) 22
78. Given this scheme procedure
(define foo (lambda (x)
(if (= x 0)
1
(* x (foo (- x 1)))
)
))what does this procedure do?
b. square(x)
c. cube(x)
d. absolute(x)
79. Which of the following forms will return an error when run? Select all that apply?
a. (+ 2 '2)
c. '(+ 2 3)
e. (define a 'a)
80. What is the return value of the code below?
(define lst '(3 5 2 9))
(min (car lst( cadr lst))a. 2
c. 4
d. error message
81. What is the correct method for constructing a pair in scheme>
a. (append 1 2)
b. (1 . 2)
c. (combine 1 2)
82. Which of the following is a scheme pair?
a. '(x . y)
b. '(x . x)
c. '()
83. Given this expression, what is the expected result?
(car (cdr '(1 2 3 4 5))
a. 1
c. 3
d. 4
84. What statement is accurate and correct for scheme lists compared to pairs?
a. every pair is a list
b. there is only one pair that is not a list
c. every list is a pair
d. there exists a list that is not a pair
85. Which of the following is equivalent to the expression below?
(car(cdr '(1 2 3 4 5))
b. (caddr '(1 2 3 4 5))
c. (cdar '(1 2 3 4 5))
d. (cacdr '(1 2 3 4 5))
86. What aspect of computation in a recursive algorithm leads to slow performance?
a. requiring a lambda form
b. using many different variables as parameters
c. deferring work until computing the recursive result
d. waiting for the preprocessor to run before compilation
87. Why is it fair to use either recursion or iteration to solve a problem like factorial?
b. because we are using scheme, other languages don't support both recursion and iteration
c. this is incorrect, factorial can only be implemented using iteration
d. this is incorrect, factorial can only be implemented using recursion
88. What is the typical design approach used in scheme algorithms
a. break functionality into little pieces and then assemble them into something more complicated
b. create objects that contain both state and behavior like in C++
c. write code that manipulates the contents of the same memory locations over and over again
d. use UML to come up with a high-level view of the program
89. A higher order function is a function that takes the
a. return val of a function as an argument
b. operator of a function as an argument
c. return values of multiple functions as arguments
d. contents of a list and processes it
90. Given this procedure, what is the expected result?
(map (lambda (x) (+ x x 2)) '(1 2 3 4 5 6))a. error message
b. (1 2 3 4 5 6)
d. (4 6 8 10 12)
91. Given this procedure, what is the expected result?
(map (lambda (x) (+ x x 2)) '(1 2 3 4 5 (6 7)))a. (1 2 3 4 5 6)
c. (2 4 6 8 10 12)
d. (4 6 8 10 12 14)
92. Filter is a higher-order function that
a. allows a variable number of arguments
b. can check the equality of all types of data
c. applies a predicate to all elements of a list
d. reduces a list of elements to a single element
93. The first implementation of mergesort only processed lists of numbers. How did higher-order programming help to make it generic and able to process more types of data?
a. the helper for getting the right side of the input was redone to not use the left helper
b. the helper defines were nested into the larger algorithm
c. parameters were added to the algorithm to specify specific procedures for examining data
d. the procedure was renamed to allow it to use non-functional programming techniques
94. Which of the following predicated in logic programming matches most closely with this statement?
"Bill listens to music or news?"
a. listensto(bill,music);listensto(bill,news).
b. listensto(Bill,music);listensto(Bill,news).
c. listensto(bill,music,news,talkshow).
d. bill(listensto,music);billl(listensto,news).
95. the key idea of logic programming paradigm is to solve a problem by describing
a. how to solve the problem in steps
b. where the problem comes from
c. the problem in a set of mathematic formulas
96. how many arguments can be defined in a fact?
a. one only
b. one or two only
c. at most three
97. a fact starts with a relationship followed by a list of arguments. the arguments of a fact
a. can be variables or simple values
b. can be variables or simple values or structures
c. must be simple values
d. must be variables
98. What notation does Prolog use for expressing arithmetic operations?
a. prefix
c. postfix
d. BNF
99. We apply an anonymous variable in the definition of a rule if we
a. want to obtain a return value to the variable
b. do not want to obtain a return value to the variable
c. want to make the variable a private variable
d. want to make the variable a public variable
100. A prolog variable represents a
b. memory location
c. constant
d. question
101. the scope of a prolog variable is
a. within the factbase
b. with the factbase and rulebase in the file
c. within a single fact, rule, or query
d. from its declaration to the end of the file
102. A goal succeeds, if there are facts(rules) that match or unify the goal. what are required in order for a goal clause and a fact to unify?
a. their predicates are the same
b. they have the same number of arguments
c. their arity must be different
d. their corresponding arguments match
103. a prolog program usually contains
c. class definitions
104. in a prolog recursive rule, what components are required?
b. size-M problem, where M < N
d. a circular definition that swaps the parameters of the rule
105. What is wrong with this piece of prolog code?
ancestor (A,D):-(A,P), ancestor(P,D)
a. it does not have a definition oft the size-N problem
b. it does not have a stoping condition
c. it has two size-M problems with difference sizes
d. it is not a tail-recursive program, and it is not efficient
106. Assume that the rule factorial(N, Fac) will compute Fac= N! What should be the output if the following question is asked?
?- factorial(2,5).
a. fac is 5
b. yes
d. instantiation error
107. if we try to use tail-recursive rules to implement non-tail-recursive rules, it will normally result in rules that are
a. more complex and more difficult to understand
b. simpler and easier to understand
c. more time consuming in execution
d. circular rules
108. a circular definition of a rule
a. is a more effective recursive definition
b. may cause an infinite loop for certain goals
c. will cause an infinite loop for every goal
d. will never cause an infinite loop
109. what programming language features are supported in prolog?
c. return different types of values
d. function as the first-class object: place a function call as an argument
110. which of the followings is equivalent to this prolog list:
[cat | [dog,pig]]?
b. [cat,[dog,pig]]
c. [cat.[dog,pig],[]]
d. [cat,[dog,pig,[]]]
111. given a prolog pair [H|T] which of the following statements are correct?
a. if T is a list, then [H|T] is list
b. if T is not a list, then [H|T] is not list
c. if H is not a list, then [H|T] is not list
d. [H|T] is always a list, regardless whether H or T is a list
112. What is the best way of writing a prolog rule that gives you all the possible coin combinations adding to a dollar?
a. use nested repeat rules
b. use recursion rules
c. use membership rules and arithmetic conditions
d. use sorting rules and selection conditions
113. which sorting algorithm has the best execution time in the worse cast scenario?
a. selection
b. insertion
d. quick
114. According to the quick sort algorithm, how can the pivot value be selected?
a. any element in the current list can be selected
c. the first element must be selected
c. the median of the list must be selected
d. the last element must be selected
115. a cut interferes with a recursive process by removing the recursive exit points. true or false?
Answer
false
116. What does the built-in predicate cut(!) do?
a. print all possible outputs automatically
b. remove all existing backtracking points
c. translate a loop into recursion
d. compute the factorial
117. cut(!) is a clause that always returns
b. false
c. an int value
d. the factorial of int
118. using a cut(!) in a rule can
a. reduce possible answers of a question that is asked using the rule
b. create an incorrect output if the rule is recursive
c. create an incorrect output if the rule is not recursive
d. increase possible answers of a question that is asked using the rule
119. prolog allows to dynamically adding facts into the factbase through the following operations
c. Retract(fact).
d. Abolish(fact).
120. the flow control clause repeat in prolog performs the following operation:
a. generate a backtracking point
b. generate a recursive return point
c. remove a backtracking point
d. remove all backtracking points
121. which of the following statements are correct about using the cut(!)
a. cut(!) has to be places at the very end of a rule
b. cut(!) can be placed anywhere in a rule, the effect is exactly the same
c. cut(!) can be placed anywhere in a rule as a condition, and the effects can be different
d. cut(!) removes all existing backtracking points, but new backtracking points can be added later
122. Event-driven computing paradigm is to
- define a set of events and write a handler for each event
 
123. In contrast to Web 1.0, what is the key function of Web 2.0?
- Web is the computing platform
 
124. What programming language impacts the readability of the programs written in this language?
Answer
- Control Structures
 - Syntax Design
 - Data Structures
 
125. What is a feature of object-oriented computing?
- encapsulation of states / state encapsulation
 
126. Which command will have a loop expressed in a syntax graph?
- switch
 
127. If your program was designed to print "Hello World" ten (10) times, but during execution, it printed eleven (11) times. What typeof error is it?
- Semantics Error
 
128. A computer program can be broke down into several structural layers. Which of the followings belong to these structural layers. Select all that applies.
Answer
- Synctatic
 - Contextual
 - Semantics
 
129. For the following BNF ruleset, which are terminal symbols? Select all that apply.
<char> ::= a | b | c | ... | x | y | z
<identifier> ::= <char> | <char> <identifier>Answer
- y
 - a
 
130. What does the I (pipe) symbol in a BNF rule mean?
- It is an "or" operation
 
131. Can the identifier "base_variable" be created from the following BNF ruleset?
<char> ::= a | b | c | ... | s | ... | x | y | z
<identifier> ::= <char> | <char> <identifier>- No - there is an underscore in the identifier name that cannot be generated.
 
132. What is the main reason of applying two-step translation of high level programming language?
- One compiler for all machines
 
133. If you like to see accurate debugging information, which of the following program processing would you recommend?
- interpretation
 
134. A final method in java defines
- an inline function
 
135. Macros-Processing in C takes place during which phase?
- Pre-processing
 
136. What is "func" in this C program example?
#include <stdio.h>
#define func(x, y) (x > y) ? y : x
int main()
{
int x = 10;
int y = 9;
int z = func(x, y);
}- A macro
 
137. Explicit type conversion is commonly refer to as
- Casting
 
138. Converting an integer value 5 to a float number 5.0 takes
- more than two machine instructions
 
139. Implicit type conversion is commonly referred to as
- Coercion
 
140. Which language will report a compilation error for the following snippet of code?
int i = 3;
double n, j = 3.0;
n = i + j;- Java
 
141. Which of the following orthogonality describe this example: If a block allows one statement, it should allow zero or more statements within that same block.
- Number orthogonality
 
142. Why do we need to flush the input buffer?
- An unformatted input can read the newline character left from the previous input operation.
 
143. The imperative programming paradigm is popular and is a part of object oriented computing paradigm, because it
Answer
- matches the culture of doing things by following the step-wise instructions.
 - is based on computer organization and thus is efficient to execute on hardware.
 
144. A data type is defined by
Answer
- the operations allowed
 - the values allowed
 
145. A variable declaration can involve the following attributes:
Answer
- scope
 - type
 
146. Where is the main() function located in a C++ program?
- outside any class
 
147. What is NOT the purpose (functionality) of the forward declaration (prototype)?
- to allow a function to return different types of values
 
148. In a given programming and execution environment, a variable declaration in C binds a name to a memory location. What are also determined in declaration?
Answer
- Variable size (number of bytes)
 - Variable type
 - Variable scope
 
149. Given a declaration: char a[] = "Hello World"; What is the size (in bytes) of the array a[]?
- 12
 
150. Given a C declaration char a[] = "Hello World"; What can be used as the initial address of array a[]?
Answer
- &a[0]
 - a
 
151. Which of the following C declarations (contextual level) will cause a compilation error?
- int d[];
 
152. Given this snippet of code, what is the value of z after executing the last statement?
int x = 10, y, *z;
z = &y;
y = &x;
*y = 100;a)10
c)100
d)1000
153. Given this snippet of code, what is the value of x after executing the last statement?
int x = 10, y, *z;
y = &x;
z = &y;
**z = 1000;a)10
b)100
d)None of these values
154. Given this snippet of code, what is the value of x after executing the last statement?
int x = 10, *y;
y = &x;
*y = 100;
y = y + 1;a)10
c)1000
d)None of these values
155. A pointer variable can take the address of a memory location as its value. Read the given program.
#include <stdio.h>
main(){
int a = 20,b = 30, p, q, **r;
p = &a;
*p = 50;
q = &b;
*q = 70;
r = &p;
**r = 90;
printf("%d\n", a); //1st printf statement
printf("%d\n", b); //2nd printf statement
a = 20;
b = 80;
printf("%d\n",**r); //3rd prints statement1. The output of the 1st printf statement is
2. The output of the 2nd printf statement is
3. The output of the 3rd printf statement is
Answer
- 90
 
2. 70
3. 20
156. Given the declaration: char A[3] = {'C', 'a', 'r'}, *p = A; what statement prints character a?
a) printf("%c", *p);
b) printf("%c", *p++);
c) printf("%c", *p+1);
157. Given the following code
char a[] = {'c', 'a', 't', '\0'};
char *p = a;
while (*p != 0) {
p = p + 1;
printf("%c", *(p++));
}What will happen?
a) A run time error will occur at the printf line.
b) It prints: a string of random characters
c) It prints: cat
158. Given the following code
char p = "hello", s = "this is a string";
p = s;
printf("%s\n", p);What will happen?
a) It prints: this is a string
b) A run time error may occur at this line: p = s;
c) A compilation error will occur at this line: p = s;
d) It prints: hello
159. Given the following C code
char a[2][3] = { { 'c', 'a', 't'}, { 'd', 'o', 'g'} };
int i, j;
for (i = 0; i<2 ; i++) {
for (j = 0; j<3; j++)
printf("%c", a[i][j]);
}What will happen?
a) A compilation error will occur at this line: printf("%c", a[i][j]);
b) It prints: cat
c) A compilation error will occur at this line: char a[2][3] = { { 'c', 'a', 't'}, { 'd', 'o', 'g'} };
160. Assume this is a 32-bit environment, what is the size of x?
struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} *x;b) 66 bytes
c) 68 bytes
d) 72 bytes
161. Assume this is a 32-bit environment, what is the size of x? (HINT: Don't forget about padding.)
struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} x;a) 4 bytes
b) 66 bytes
d) 72 bytes
162. Assume pointer variable p points to node x of a linked list, and node x's next pointer points to node y. What does free(p) operation mean?
a) return the memory held by x to the free memory pool.
b) return the memory held by x and by y to the free memory pool
c) set pointer p to 0.
d) return the memory held by x to the free memory pool and set pointer p to 0.
163. Given the information below, how do you insert a new node, p, to the beginning of a linked-list. Assume head is pointing to the first node in the linked-list.
struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} head, p;b) head = p;
c) p->next = head;
d) head = p;
p->next = head;
164. Given the information below, which of the following snippet of C code will print every terminal in the linked list without any side-effects of changing the state. Assume head is the only reference to the linked list and there are more than one terminal in the list.
struct Terminal {
char name[30];
char location[32];
struct Terminal* next;
} head, x;
Answer
x = head;
while(x != NULL) {
printf("%s - %s", x->name, x->location);
x = x->next;
}
165. The data structure that stores the Frequently Brought Together (FBT) list in Amazon's recommendation system is linked to
b) the items in the shopping cart only
c) the items in the checkout list cart only.
d) the items that are marked with "Amazon's Choice".
166. What is the difference between call-by-address and call-by-alias?
a) Call-by-address can modify the variable outside the function, but call-by-alias cannot.
b) Call-by-alias can modify the variable outside the function, but call-by-address cannot.
c) Call-by-alias involves one variable only, while call-by-address involves two variables.
d) The actual parameter in call-by-address has to be a variable, while the actual parameter in call-by-alias can be a variable or a constant.
167. Given the snippet of codes, identify the passing mechanism used for y (in func).
void func(int *x, int &y)
{
x = x + y;
y = 2;
}a) call-by-value
b) call-by-address
d) call-by-pointer
168. Given this snippet of codes, identify the passing mechanism used for y (in func).
void func(int *x, int y)
{
x = x + y;
y = 2;
}b) call-by-address
c) call-by-alias
d) call-by-pointer
169. Which parameter passing mechanism does not have side-effects?
b) call-by-address
c) call-by-alias
d) call-by-pointer
170. Stored Program Concept (von Neumann machine) is one of the most fundamental concepts in computer science. What programming paradigm most closely follows this concept?
- imperative
 
171. A set of basic principles, concepts, and methods for how a computation or algorithm is expressed
- paradigm
 
172. The programming paradigm that expresses computation by fully-specified and fully-controlled manipulation of named data in a stepwise function
- imperative
 
173. Another term for the imperative paradigm
- procedural
 
174. The programming paradigm that is basically the same as the imperative paradigm except that related variables and operations on variables are organized into classes of objects
- object-oriented
 
175. The programming paradigm that expresses computation in terms of mathematical functions
- functional
 
176. Another term for the functional paradigm
- applicative
 
177. The programming paradigm that expresses computation in terms of logic predicates
- logic
 
178. Another term for the logic paradigm
- declarative
 
179. If you teach someone to make a pizza, you are in fact teaching (functional, imperative) programming.
- imperative
 
180. If you teach someone to order a pizza from a restaurant, you are in fact teaching (functional, imperative) programming.
- functional
 
181. Because of hardware constraints, early programming languages emphasized _____.
- readability or efficiency.
 
182. The main idea of structured programming is to
A) increase the types of control structures,
B) make programs execute faster,
C) reduce the types of control structures,
D) use BNF to define the syntactic structure.
183. A meta language that can be used to define the lexical and syntactic structures of another language
- Backus-Naus Form
 
184. Which programming language allows the mixed use of data types? (Ada, C, Java, All of them)
- C
 
185. In the layers of programming structure, which layer performs type checking?
- contextual
 
186. Which programming structure defines the program semantics before dynamic execution?
- contextual
 
187. Another term for contextual structure
- static semantics
 
188. Which programming structure describes the meaning of a program during the execution?
- semantic structure
 
189. Which programming structure defines the grammar of forming sentences or statements using the lexical units?
- syntactic structure
 
190. Which programming structure defines the vocabulary of a language?
- lexical structure
 
191. Interpretation is not efficient if
A) multi-module programming is used,
B) the difference between source and destination is small,
C) the source program is small, or
D) the source program is written in an assembly language.
192. A machine language with sophisticated use of mnemonics
- assembly language
 
193. The direct execution of one statement at a time sequentially by the interpreter
- interpretation
 
194. First translates all the statements of a program into assembly language code or machine code before any statement is executed
- compilation
 
195. (Inclining, Macro) is a suggestion to the compiler, while (inlining, macro) will be enforced.
- Inlining, macro
 
196. The phase prior to the code translation to the assembly or machine code
- preprocessing
 
197. Macros processing takes place during which phase?
- preprocessing
 
198. Assume a program requires 20 lines of machine code and will be called 10 times in the main program. You can choose to implement it using a function definition or a macro definition. Compared with the function definition, macro definition will lead the compiler to generate, for the entire program, (longer, shorter, the same length of) machine code and (longer, shorter, the same) execution time.
- longer, shorter
 
199. In a (strongly, weakly) typed language, every name in a program must be associated with a single type that is known at the compilation time.
- strongly
 
200. In a (strongly, weakly) typed language, name equivalence is used.
- strongly
 
201. Two types are equivalent only if they have the same name
- name equivalence
 
202. In a (strongly, weakly) typed language, every type inconsistency must be reported.
- strongly
 
203. Is C++ a strongly or weakly typed language?
- strongly
 
204. Is Java a strongly or weakly typed language?
- strongly
 
205. Are functional programming languages usually strongly or weakly typed languages?
- weakly
 
206. Is ML a strongly or weakly typed language?
- strongly
 
207. In a (strongly, weakly) typed language, not every name has to be associated with a single type at the compilation time.
- weakly
 
208. In a (strongly, weakly) typed language, structural equivalence is used.
- weakly
 
209. In a (strongly, weakly) typed language, a variable of a subtype is acceptable and coercion is allowed.
- weakly
 
210. Implicit type conversion is commonly referred to as:
- coercion
 
211. Two types are equivalent if they have the same set of values and the same operations
- structural equivalence
 
212. Is C a strongly or weakly typed language?
- weakly
 
213. Is Scheme a strongly or weakly typed language?
- weakly
 
214. Is Prolog a strongly or weakly typed language?
- weakly
 
215. Are typeless languages strongly or weakly typed?
- weakly
 
216. Is BCPL a strongly or weakly typed language?
- weakly
 
217. The property of straight lines meeting at right angles or independent random variables
- orthogonality
 
218. If one member of the set of features S1 can be combined with one member of the set of features S2, then all members of S1 can be combined with all members of S2. What kind of orthogonality is this?
- compositional
 
219. If one member of the set of features S1 can be combined with one member of the set of features S2, then this member of S1 can be combined with all members of S2. What kind of orthogonality is this?
- sort
 
220. If one member of the set of features S is allowed, then zero or multiple features of S are allowed. What kind of orthogonality is this?
- number
 
221. Is an inline function or a macro more efficient in execution time?
- macro
 
222. Is an inline function or a macro easier for programmers to write?
- inline function
 
223. A method that cannot be overridden in a subclass
- final
 
224. Assigns a literal value or an expression to a variable
- assignment
 
225. Tests a condition and branches to a certain statement based on the test result
- conditional statements
 
226. Tests a condition and enters the body of the loop or exits the loop based on the test result
- loop statement
 
227. Names that can be chosen by programmers to represent objects like variables, labels, procedures, and functions
- identifiers
 
228. Names reserved by the language designer and used to form the syntactic structure of the language
- keywords
 
229. Symbols used to represent the operations
- operators
 
230. Symbols used to separate lexical or syntactic units of the language
- separators
 
231. Values that can be assigned to variables of different types
- literals
 
232. Any explanatory text embedded in the program
- comments
 
233. A graphic form of notation often used to supplement the readability of BNF notation
- syntax graph
 
234. Another term for syntax graph
- railroad tracks
 
235. A declaration of an identifier for which the programmer has not yet given a complete definition
- forward declaration
 
236. Statements in a function form a conceptual unit
- abstraction
 
237. Forward declaration in modern programming practice
A) is never necessary,
B) is not required if <iostream> is included,
C) is useless, or
D) provides a level of abstraction.
238. C language does not have a Boolean type because
A) Boolean values can be represented as integers,
B) C is not designed to handle logic operations,
C) C uses strong type checking, or
D) C++ already defined a Boolean type.
239. Two functions are mutually recursive functions if
A) each function calls itself,
B) one function is defined within the other function,
C) they are independent of each other, or
240. Assume that a string is declared as char str[] = "alpha", what is the return value of sizeof(str)?
- 6
 
241. Assume that two pointers are declared as char str1 = "alpha", str2. Which of the following assignment statements will lead to a semantic error?
A) str2 = str1,
B) str2 = 0,
C) str1 = str1 + 1, or
242. Which of the following declarations will cause a compilation error?
A) char s[5],
B) char s[3] = "hello",
D) char s[] = {'s', 't', 'r'}
243. Given a declaration: int i = 25, j = &i, k = &j; which of the following operations will change the value of variable i?
A) j++,
B) k++,
C) (k)++, or
244. Given a declaration: int i = 25, j = &i, k = &j; which of the following operations will cause a compilation error?
A) i++,
C) (j)++, or
D) (**k)++
245. What is the maximum number of padding bytes that a compiler can add to a structure?
- more than 3
 
246. What parameter-passing mechanism cannot change the variable values in the caller?
- call-by-value
 
247. The parameters we used when we declare a function
- formal parameters
 
248. The values or variables we used to substitute for the formal parameters when we call a function
- actual parameters
 
249. The parameter-passing mechanism in which a formal parameter is a local variable in the function
- call-by-value
 
250. The parameter-passing mechanism in which the formal parameter is an alias name of the actual parameter
- call-by-alias
 
251. Name the other two terms for call-by-alias
Answer
- call-by-reference,
 - call-by-variable
 
252. The parameter-passing mechanism in which the address of the actual parameter is passed into a local variable of the function
- call-by-address
 
253. Name the other term for call-by-address
- call-by-pointer
 
254. What parameter-passing mechanism requires the actual parameter to be a variable?
- call-by-alias
 
256. Given the forward declaration: void foo(int m, int &n); What parameter passing is used?
- call-by-alias
 
257. What type of recursive function is structurally equivalent to a while-loop?
- tail-recursion
 
258. How many bits are in a byte?
- 8
 
259. Temporary storage in the CPU that holds the data the processor is currently working on
- register
 
260. Holds the program instructions and the data the program requires
- RAM
 
261. What are the four aspects of a variable?
- value, location, address, name
 
262. What are the three different ways to introduce constants in C/C++?
- macro, const qualifier, enumeration constant
 
263. Can a constant defined by const ever be modified?
- No
 
264. A region of shared memory that, over time, can contain different types of values
- union type variable
 
265. What parameter passing mechanism is used when the parameter is a variable?
- call-by-value
 
266. What parameter passing mechanism is used when the parameter is an address?
- call-by-alias
 
267. What parameter passing mechanism is used when the parameter is a pointer?
- call-by-address
 
268. C / C++, Fully specified and fully controlled manipulation in a step-wise fashion
- Imperative (Procedural) Programming key idea
 
269. LISP, Focus on higher level of abstraction
- functional paradigm key idea
 
270. what is an identifier (names of variales, functions, methods classes)
keywords (if, switch, for, int, float)
Operators + * >=
delimiters {}
literals 5, 14.5, 'a'
comments //
/ /- lexical rules define categories/tokens
 
271. Functional programming languages are low-level languages
- false
 
272. What kind of error is in the following line:-
int a = ((245)(6/2) hello (4+90));- syntatic
 
273. Which of the following programs are correct in C?
typedef int booOoolean;
typedef char FlagType;
int main() {
booOoolean x = 0;
int counter; FlagType xx = 'A'; // comment
}274. Which code can be used to create a contact and store data ?
struct contact x;
scanf("%s", x.name);
scanf("%d", &x.phone);
scanf("%s", x.email);275. In C++, implementations of member functions cannot be inside the class definition (for short functions) or outside of the class definition.
- false
 
276. Which of the following classes creates and initializes correctly an static variable in C++?
class Something {
public:
static int v;
};
int Something::v = 1;277. What is the major improvement of structured programming languages over the earlier programming languages?
- Removing Goto statement from the language
 
278. What programming language characteristics impact the readability of the programs written in this language?
- Control structures, syntax design, Data Structures
 
279. What programming paradigm does Fortran belong to?
- Imperative
 
280. Which commands (constructs) do NOT have a loop when expressed in syntax graphs?
if-then-else
for(<init-expr>; <test-expr>; <increment-espr>){<statements>}
while (condition) do {statements}281. How many different identifiers can the following BNF ruleset generate?
<char> ::= a | b | c |...| x | y | z
<identifier> ::= <char> | <char> <identifier>
more than 26282. which of the following cannot be checked by an imperative or object-oriented compiler?
- Semantics
 
283. Which command will have a loop when expressed in a syntax graph?
- Switch
 
284. If your program was designed to print "Hello World" ten times, but during execution, it printed eleven times, what type of error is it?
- Semantics error
 
285. If your application is composed of multiple modules (programs), which of the following program processing would you recommend?
- Compilation
 
286. What is the main reason of applying two-step translation of high level programming languages?
- one compiler for all machines
 
287. Which of the following are correct if a language is strongly typed?
- each name in a program has a single type associated with it, type errors are always reported
 
288. Type checking happens during the compilation phase, it reinforces which of the following structural layers?
- Contextual
 
289. (True or False) Sort orthogonality 1 and sort orthogonality 2 implies compositional orthogonality
- True
 
290. In the C-Style input function scans("%d", &i), what does the character '&' mean?
- scanf takes the address of a variable as its parameter
 
291. In C, what function can be used for inputting a string containing spaces?
- fgets();
 
292. The forward declaration of a function requires:
- return type, function name, parameter types
 
293. Which of the following is a C++ type, but not a C type?
- Bool
 
294. In the memory hierarchy of a computer system, which type of memory is the fastest one?
- Registers
 
295. What IS the purpose (functionality) of the forward declaration (prototype)?
- to serve as an index to the functions, to satisfy scope rule, to allow functions to be ordered in any way, to allow mutually recursive functions
 
296. Multiple pointers can reference (point to) the same object
- True
 
297. A pointer variable can take the address of a memory location as its value. Read the given program.
#include <stdio.h>
main(){
int i = 10, j = 20. p, q, **r;
p = &i;
*p = 40;
q = & j;
*q = 60;
r = %p;
**r = 80;
printf("%d\n", i);
printf("&d\n", j);
i = 10;
j = 70;
printf("%d\n", **r);
}Answer
1. 80
2. 60
3. 10
298. Given this snippet of code, determine which of the following options will change the text in array to "Hello Doe" after execution. (Check all that apply.)
char array[] = "Hello Joe";
char *x;Answer
x = array;
*(x + 6) = 'D';
and
x = &array[0];
x = x + 6;
*x = 'D';
299. Given the C declaration:
char a[] = "Hello";char p = a, q;what operations are valid syntactically? Select all that apply.
Answer
q = &(*p);
and
q = (&a[0]);
300. What data types in C have the same data range, assuming that the computer is a 32-bit computer?
- pointer type and unsigned int
 
301. Given the following definition and declarations:
#define size1 10
const int size2 = 20;
char a1[size1];
char a2[size2];which line of code can cause a compilation error?
Answer
char a2[size2];
302. Given the following snippet of code, answer the following two questions based on the code:
typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} days;
days x = Mon, y = Sat;
while (x != y) { x++; }
y++;
printf("x = %d, y = %d", x, y);Answer
x = 6
y = 7
303. Consider the following snippet of code in a 32-bit computer.
#define max 10
struct contact {
char name[30];
char email[30];
int phone;
};
struct contact A[max];What is the size of the entire array A in bytes?
- 640
 
304. Consider the following snippet of code in a 32-bit computer.
struct contact {
char name[30];
char email[30];
int phone;
} x;What is the size of variable x in bytes?
- 64
 
305. When is padding required for a structure type variable?
- When the structure contains a word-type variable such as integer, float and pointer, and the total number of bytes is not a multiple of four
 
306. the size (number of bytes) of a structure-type variable can be changed by the following factors:
- adding a member into the structure, changing the orders of the members in the structure, changing the computer from a 32-bit to a 64-bit processor
 
307. The reason that we use a buffer between the disk and the memory is
- disk access speed is low, but large blocks of data can be read from and written to the disk
 
308. What parameters are required when performing file operations fread and fwrite?
- destination, source, item size, number of items
 
309. The reason that we need to call fflush() or cin.ignore() is because the previous
- input leaves a character in the file buffe
 
310. Given the information below, how will you access the name of the third terminal node in the linked-list? Assume head is pointing to the first terminal node and there are at least 3 terminals in the linked-list.
struct Terminal { char name[30]; char location[32]; struct Terminal next;} head;
- head->next->next->name
 
311. Assume that you want to delete the entire linked list pointed to by head. Which of the following deletion operation will cause the most garbage of memory?
- head = null;
 
312. How do you properly delete the first node of a linked list pointed to by head, assuming that the linked list is not empty and temp is another pointer of the same type?
temp = head;
head = head->next;
free(temp);313. The data structure that stores the Frequently Bought Together (FBT) list in Amazon's recommendation system is linked to
- each item in the catalog
 
314. Which of the following statements is true?
- a constant cannot be used as the actual parameter for call-by-alias
 
315. which of the following statements is false?
Answer
a global variable cannot be used as the actual parameter for call-by-alias,
a structure type of variable cannot be as the actual parameter for call-by-value,
a constant cannot be used as the actual parameter for call-by-address,
the return type of a function cannot be a pointer
316. Given this snippet of codes, what is the expected output?
void func(int *x, int y){
x = x + y;
y = 2;
}
void main(){
int x = 10, y = 10;
func(&x, y);
printf("x: %d, y: %d", x, y);
}Answer
x: 20, y: 10
317. What computing paradigm can solve a problem by describing the requirements, without writing code in a step-wise fashion to solve the problem?
- Logic
 
318. What computing paradigm enforces stateless (no variable allowed) programming?
- Functional
 
319. What factor is generally considered more important in modern programming language design?
- Readability
 
320. In the following pseudo code, which programming languages allows the mixed use of data types?
int i = 1; char c = 'a';
c = c + 1;- C
 
321. n the layers of programming language structure, which layer performs type checking?
- Contextual
 
322. Which of the following statements is correct if a language is strongly typed?
- each variable in a program has a single type associated with it and type errors are always reported
 
323. The contextual structure of a programming language defines
- the static semantics that will be checked by the compiler
 
324. If a program contains an error that divides a number by zero at the execution time, this error is a
- semantic error
 
325. What is the difference between an inline function and a macro in C++?
- Inlining is a suggestion to the compiler, while a macro definition will be enforced
 
326. Assume a function requires 20 lines of machine code and will be called 10 times in the main program. You can choose to implement it using a function definition or a macro definition. Compared with the function definition, macro definition will lead the compiler to generate, for the program,
- a longer machine code, but a shorter execution time
 
327. Forward declaration in modern programming practice
- provides a level of abstraction
 
328. C language does not have a Boolean type because
- Boolean values can be represented as integers
 
329. Two functions are said to be mutually recursive if
- they call each other
 
330. The enumeration type of values are stored in the memory as
- Int
 
331. If we want to store a linked list of structures, with each structure containing different types of data, into a disk file, what file type should we choose?
- binary file
 
332. Assume the following structure is defined in a 32-bit programming environment. What is the size of y?
struct myNode{
char name[30];
char location[32];
struct myNode* next;
} x, *y;- 4 bytes
 
333. Given the forward declaration:
void foo(char c, int &n); what parameter passing mechanisms are used?
- call-by-value and call-by-alias
 
334. The Ackermann function is defined recursively for two nonnegative integers k and n as follows. Answer the question based on the function and the fantastic-four abstract approach. What is the stopping condition and return value at the stopping condition?
- s = 0 and t+1
 
335. The Ackermann function is defined recursively for two nonnegative integers k and n as follows. Answer the question based on the function and the fantastic-four abstract approach. What is the size-n problem?
- A(s,t)
 
336. The Ackermann function is defined recursively for two nonnegative integers k and n as follows. Answer the question based on the function and the fantastic-four abstract approach. What is the size-m problem that can be used for calculating the size n problem?
Answer
A(s-1, 1)
A(s, t-1)
A(s-1, A(s, t-1))
337. The data stored in a binary search tree is sorted if the tree is traversed in
(ex. missing)
- Inorder
 
338. Consider an array, a linked list, doubly linked list and a binary search tree. Which data structure requires the fewest comparisons in average to search an element stored in the data structure?
- binary search tree
 
339. Given this snippet of code, identify the stopping condition and the return value.
void deleteList(struct contact* node) {
if (node == NULL) return;
else {
deleteList(node->next);
free(node);
}
}- if (node == NULL) return;
 
340. A merge-sort is typically implemented using
- a function with two recursive calls.
 
341. A tail-recursive function is structurally equivalent to
- a while loop
 
342. Which recursive functions require us to define more than one size-m problem?
- Hanoi tower, Mergesort function
 
343. What is the time complexity of the insertion sort algorithm?
- O(n*n)
 
344. The function searching a binary search tree can be easily implemented using a
- a recursive function with two recursive calls.
 
345. The search algorithm will be more efficient if a binary search tree is
- a balanced binary tree.
 
346. The complexity of searching a balanced binary search tree is the order of
- O(lg n)
 
347. What are the key features of object orientation in programming languages? Select all that apply.
- Dynamic memory allocation,
 - Encapsulation of state
 
348. The purpose of the scope resolution operator is to allow a function to be
placed outside the class.
349. Which C/C++ operations will acquire memory from heap? Select all that apply.
Choices: (malloc, new, free, declaration)
- malloc,
 - new
 
350. If a function calls another function, the local variables in these two functions use the memory from
- different stack frames.
 
351. How is Java's garbage collection implemented?
- It uses a reference counter to indicate if an object is still referenced by any variable.
 
352. What is the key difference between a static variable and a global variable?
- They come from different parts of memory.
 
353. Given the snippet of code:
int x = 5;
int bar(int j) {
int *k = 0, m = 5;
k = &m;
return (j+m);
}
void main(void) {
static int i =0;
i++;
i = bar(i) + x;
}Which variables obtain their memory from the stack? Select all that apply. Choices(I,j,k,m,x)
- j,k,m
 
353. What is the best way of deleting a linked list of objects in C++?
- Use a loop to delete every object in the linked list.
 
354. We need to write a destructor for a class, if
- heap memory is used in the constructor of the class.
 
355. A piece of memory must be explicitly garbage-collected, if it comes from
- heap
 
356. What is the best way of deleting an array created by "p = new StructType[size];" in C++?
- delete[] p;
 
357. What members of a base class can be redefined in the derived classes?
- virtual members
 
358. The semantics of multiple inheritance becomes complex and error prone, if the base classes have
- overlapped members.
 
359. Given the code as follows:
main()
{
int i = 3, n;
float x;
x = i;
n = 8 % x;
}What problem will occur?
- A compilation error will occur.
 
360. If A is the base class and B is a class derived from A, and x and y are pointers to objects of A and B, respectively, which assignment statement can pass the compiler check?
- x = y;
 
361. Given the following class definition and the variable declaration:
class employee
char *name;
long id;
}
class manager {
employee empl;
char* rank;
} xWhich of the following assignment statement is correct?
- x.empl.id = 12345;
 
362. What type casting mechanism should be used if you want to change pointer type for pointing to a different object in an inheritance hierarchy?
- dynamic_cast
 
363. In a pure object-oriented language, all data should be objects, and all objects should be accessed by
- reference (pointer) only.
 
364. Given the following snippet of C++ code:
string name = "Hello";
ofstream myFile;
myFile.open(myFile);
myFile << name;
myFile.close();What does it do?
- It saves the word Hello into a file in the file system.
 
365. What keyword is used for defining an exception handler?
- catch
 
366. What type of values can a throw-statement throw (return)?
Choices:(Primitive type, String type, Object types, All of the above)
- All of the above.
 
367. C++ exception handling mechanisms will make sure
- the stack pointer returns to its original position, deleting all heap objects constructed in the constructor.
 
368. Functional programming languages do NOT allow us to define
- variables whose value can be modified.
 
369. One of the major differences between the imperative and functional programming languages is that the functional programming languages do NOT
- have side-effects.
 
370. In Scheme, the form (symbol-length? 'James) will return:
- an error message
 
371. What notation requires parentheses in order to correctly define the order of computation?
- infix notation
 
372. Convert the following expression into prefix-p notation (Scheme statement): 10 + (5 - 3) + 2 / 4
Answer
- (+ 10 (- 5 3) (/ 2 4))
 
373. What is the return value of the code below?
(define lst '(3 5 2 9))
(min (min (car lst) (cadr lst)) (min (caddr lst) (cadddr lst)))
Answer
- 2
 
374. Given this procedure, what is the return result?
(define (guess value)
(cond ((number? value) "I'm a number")
((char? value) "I'm a character")
((integer? value) "I'm a integer")))
(guess 10)- "I'm a number"
 
375. Given an expression: x1 + x2 + x3 + x4
Which language allows us to evaluate the expression in this order: (1) x1 plus x2; (2) x3 plus x4; (3) sum of ( x1 + x2 ) plus sum of ( x3 + x4 );
- scheme
 
376. What functional feature does the code below best exhibit?
(define start-engine (lambda ()(error-detection (wheel-velocity (wheel-sensor)) (body-velocity))))
- procedures are first class objects.
 
377. The display form (display "Hello") violates the functional paradigm because it
- does not have a return value.
 
375. A let-form in Scheme is equivalent to
- an unnamed procedure.
 
376. Given the Scheme code, answer the following questions.
((lambda (x)
((lambda (x y)
(+ x y))
4 (* 6 x)))
3)(1) The value to be passed to the parameter y is …..
(2) The final output of the piece of code is …..
Answer
- 18
 - 22
 
377. The Scheme form (char? #\5) will return
- true (#t)
 
378. Given the Scheme code below, answer the following questions related the Fantastic Four abstract approach.
(define dtob (lambda (N) ; line 1
(if (= N 0) (list 0) ; line 2
(append (dtob (quotient N 2)) ; line 3
(list (remainder N 2)))))) ; line 4
(1) What line of code defines the stopping condition and the return value?
(2) What line of code contains the size-M problem, where M < N?
(3) What lines of code define the step that construct the solution to size-N problem? Choose
Answer
1) Line2
2) Line3
3) Lines 3 and 4
379. What is the correct method for constructing a pair in Scheme?
- (cons 1 2)
 
380. What statement is accurate and correct?
- There is only one Scheme list that is not a pair.
 
381. Given this expression, what is the expected result?
(car (cdr '(1 2 3 4 5))
Answer
- 2
 
382. Given the following Scheme definition:
(define reduce
(lambda (op base x)
(if (null? x)
base
(op (car x) (reduce op base (cdr x)) )))
)What parameter passing mechanism is used for the parameter op in this code?
- call-by-name
 
383. Given this procedure, what is the expected result?
(map (lambda (x) (+ x x 2)) '(1 2 3 4 5 6))
Answer
- (4 6 8 10 12 14)
 
384. Filter is a higher-order function that
- applies a predicate to all elements of a list.
 
385. Which predicate logic matches most closely with this statement?
"Bill likes chocolate and cookies."
Answer
- likes(bill, chocolate), likes(bill, cookies).
 
386. Which predicate logic matches most closely with this statement?
"Bill listens to music or news."
Answer
- listensto(bill, music); listensto(bill, news).
 
387. A goal succeeds, if there are facts (rules) that match or unify the goal. What are required in order for a goal clause and a fact to unify? Select all that apply.
- their predicates are the same, they have the same number of arguments, their corresponding arguments match.
 
388. What notation does Prolog use for expressing arithmetic operations?
- infix notation
 
389. A prolog program may contain: (Select all that apply.)
Answer
- facts
 - rules
 - questions
 
390. How many arguments can be defined in a fact?
- n, where n >= 0
 
391. The scope of a Prolog variable is
- within a single fact, rule, or query.