CSE 240 MIDTERM QUESTIONS AND ANSWERS
What key feature of programming languages is supported by C++, but not Java? -
Answers :Pointers
In contrast to Web 1.0, what is the key function of Web 2.0? - Answers :Web is the
computing platform
What computing paradigm enforces stateless (no variable allowed) programming? -
Answers :Functional
What computing paradigm can solve a problem by describing the requirements, without
writing code in a step-wise fashion to solve the problem? - Answers :logic
What is the major improvement of structured programming languages over the earlier
programming languages? - Answers :Removing Goto statement from the language.
What is a feature of object-oriented computing? - Answers :encapsulation of states
What programming languages better prepare you for leaning database query languages
such as SQL and LINQ? - Answers :Prolog and Scheme
Event-driven computing paradigm is to: - Answers :define a set of events and write an
event handler for each event
What programming language characteristics impact the readability of the programs
written in this language? - Answers :Control structures, Syntax design, and Data
Structures
Given the following code, what is the expected value for z?
#include <stdio.h>
#define func(x, y) (x > y) ? y : x
int main()
{
int x = 10;
int y = 9;
int z = func(++x, y++);
} - Answers :10
Explicit type conversion is commonly referred to as __________ . - Answers :Casting.
If you like to see accurate debugging information, which of the following program
processing would you recommend? - Answers :Interpretation
,What is the main reason of applying two-step translation of high level programming
language? - Answers :One compiler for all machines
Can the identifier "base_variable" be created from the following BNF ruleset?
<char> ::= a | b | c | ... | s | ... | x | y | z
<identifier> ::= <char> | <char> <identifier> - Answers :No - there is an underscore in
the identifier name that cannot be generated.
ow many different identifiers can the following BNF ruleset generate?
<char> ::= a | b | c | ... | x | y | z
<identifier> ::= <char> | <char> <identifier> - Answers :More than 26.
Which commands (constructs) do NOT have a loop when expressed in syntax graphs?
Select all that apply - Answers :If-then-else, for ( <init-expr>; <test-expr>; <increment-
expr> ) {<statements>} , while (condition) do {statements;}
Given this snippet of code in C,
char alpha = 'a';
int numeric = alpha + 10;
which of the following statement is correct: - Answers :Syntactically correct, but
contextually incorrect.
What is "func" in this 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);
} - Answers :A macro
Which implementation of a function has potentially the best performance in terms of
execution speed? - Answers :macro
Given the following code, what is the expected value for z?
#define func(x, y) (x > y) ? y++ : x++
,int main()
{
int x = 10;
int y = 9;
int z = func(x, y);
} - Answers :9
For the following BNF ruleset, which are terminal symbols? (Check all that apply.)
<char> ::= a | b | c | ... | x | y | z
<identifier> ::= <char> | <char> <identifier> - Answers :y, a
If a program contains an error that divides a number by zero at the execution time. This
error is a - Answers :semantic error
Java uses which of the following program processing? - Answers :Two Step Translation
with Intermediate Code -- (Compilation + Interpretation)
During compilation, linker is used for - Answers :resolving external references (bring in
code from other libraries).
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 entire program, - Answers :a longer machine code but with shorter
execution time.
A final method in Java defines: - Answers :an in-line function
Type checking happens during compilation phase, it reinforces which of the following
structural layer? - Answers :Contextual
Given the C declaration: char s1[4], s2[ ] = "hello"; if a string copy function strcpy(s1, s2)
is executed, what will happen? - Answers :The result is s1 will contain the string "hell",
and the following two byte locations will contain 'o' an '\0'.
Given a C declaration: char a[] = "Hello World"; What can be used as the initial address
of array a[]? Select all correct answers. - Answers :a,&a[0]
Assume this is a 32-bit environment, given a declaration: int a[10]; What is the size (in
bytes) of the entire array? - Answers :40
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. - Answers
:Number Orthogonality.
, In the C-Style input function scanf("%d", &i); What does the character "&" mean? -
Answers :scanf takes the address of an variable as its parameter.
Where is the main() function located in a C or C++ program? - Answers :outside any
class
The imperative programming paradigm is popular and is a part of object-oriented
computing paradigm, because it ____ (Select all answers that apply). - Answers :is
based on computer organization and thus is efficient to execute on hardware, matches
the culture of doing things by following the step-wise instructions.
Assume a variable is declared in a block of code within a pair of curly braces. The
scope of the variable ______ - Answers :starts from its declaration point and extends to
the end of the block.
What is NOT the purpose (functionality) of the forward declaration (prototype)? -
Answers :to allow functions to return different types of values.
Which of the following types is a C++ type, but NOT a C type? - Answers :bool
In C++, what function can be used to input a string with spaces? - Answers
:cin.getline(...);
During data declaration, a name is binded to a memory location, what else can be
identify as part of this process? - Answers :Data type, Scope, Qualifier
Given a declaration: char a[] = "Hello World"; What is the size (in bytes) of the array a[]?
- Answers :12
(True or False) Sort orthogonality 1 and sort orthogonality 2 implies compositional
orthogonality. - Answers :True
C/C++ has 2 pointer operators, which operator will return the address of variable? -
Answers :Ampersand (&)
Multiple pointers can reference the same object. - Answers :True
Given the following code
char *p = "hello", *s = "this is a string";
strcpy(p, s);
printf("%s\n", p);
What will happen? - Answers :A run time error may occur at this line: strcpy(p, s);
What key feature of programming languages is supported by C++, but not Java? -
Answers :Pointers
In contrast to Web 1.0, what is the key function of Web 2.0? - Answers :Web is the
computing platform
What computing paradigm enforces stateless (no variable allowed) programming? -
Answers :Functional
What computing paradigm can solve a problem by describing the requirements, without
writing code in a step-wise fashion to solve the problem? - Answers :logic
What is the major improvement of structured programming languages over the earlier
programming languages? - Answers :Removing Goto statement from the language.
What is a feature of object-oriented computing? - Answers :encapsulation of states
What programming languages better prepare you for leaning database query languages
such as SQL and LINQ? - Answers :Prolog and Scheme
Event-driven computing paradigm is to: - Answers :define a set of events and write an
event handler for each event
What programming language characteristics impact the readability of the programs
written in this language? - Answers :Control structures, Syntax design, and Data
Structures
Given the following code, what is the expected value for z?
#include <stdio.h>
#define func(x, y) (x > y) ? y : x
int main()
{
int x = 10;
int y = 9;
int z = func(++x, y++);
} - Answers :10
Explicit type conversion is commonly referred to as __________ . - Answers :Casting.
If you like to see accurate debugging information, which of the following program
processing would you recommend? - Answers :Interpretation
,What is the main reason of applying two-step translation of high level programming
language? - Answers :One compiler for all machines
Can the identifier "base_variable" be created from the following BNF ruleset?
<char> ::= a | b | c | ... | s | ... | x | y | z
<identifier> ::= <char> | <char> <identifier> - Answers :No - there is an underscore in
the identifier name that cannot be generated.
ow many different identifiers can the following BNF ruleset generate?
<char> ::= a | b | c | ... | x | y | z
<identifier> ::= <char> | <char> <identifier> - Answers :More than 26.
Which commands (constructs) do NOT have a loop when expressed in syntax graphs?
Select all that apply - Answers :If-then-else, for ( <init-expr>; <test-expr>; <increment-
expr> ) {<statements>} , while (condition) do {statements;}
Given this snippet of code in C,
char alpha = 'a';
int numeric = alpha + 10;
which of the following statement is correct: - Answers :Syntactically correct, but
contextually incorrect.
What is "func" in this 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);
} - Answers :A macro
Which implementation of a function has potentially the best performance in terms of
execution speed? - Answers :macro
Given the following code, what is the expected value for z?
#define func(x, y) (x > y) ? y++ : x++
,int main()
{
int x = 10;
int y = 9;
int z = func(x, y);
} - Answers :9
For the following BNF ruleset, which are terminal symbols? (Check all that apply.)
<char> ::= a | b | c | ... | x | y | z
<identifier> ::= <char> | <char> <identifier> - Answers :y, a
If a program contains an error that divides a number by zero at the execution time. This
error is a - Answers :semantic error
Java uses which of the following program processing? - Answers :Two Step Translation
with Intermediate Code -- (Compilation + Interpretation)
During compilation, linker is used for - Answers :resolving external references (bring in
code from other libraries).
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 entire program, - Answers :a longer machine code but with shorter
execution time.
A final method in Java defines: - Answers :an in-line function
Type checking happens during compilation phase, it reinforces which of the following
structural layer? - Answers :Contextual
Given the C declaration: char s1[4], s2[ ] = "hello"; if a string copy function strcpy(s1, s2)
is executed, what will happen? - Answers :The result is s1 will contain the string "hell",
and the following two byte locations will contain 'o' an '\0'.
Given a C declaration: char a[] = "Hello World"; What can be used as the initial address
of array a[]? Select all correct answers. - Answers :a,&a[0]
Assume this is a 32-bit environment, given a declaration: int a[10]; What is the size (in
bytes) of the entire array? - Answers :40
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. - Answers
:Number Orthogonality.
, In the C-Style input function scanf("%d", &i); What does the character "&" mean? -
Answers :scanf takes the address of an variable as its parameter.
Where is the main() function located in a C or C++ program? - Answers :outside any
class
The imperative programming paradigm is popular and is a part of object-oriented
computing paradigm, because it ____ (Select all answers that apply). - Answers :is
based on computer organization and thus is efficient to execute on hardware, matches
the culture of doing things by following the step-wise instructions.
Assume a variable is declared in a block of code within a pair of curly braces. The
scope of the variable ______ - Answers :starts from its declaration point and extends to
the end of the block.
What is NOT the purpose (functionality) of the forward declaration (prototype)? -
Answers :to allow functions to return different types of values.
Which of the following types is a C++ type, but NOT a C type? - Answers :bool
In C++, what function can be used to input a string with spaces? - Answers
:cin.getline(...);
During data declaration, a name is binded to a memory location, what else can be
identify as part of this process? - Answers :Data type, Scope, Qualifier
Given a declaration: char a[] = "Hello World"; What is the size (in bytes) of the array a[]?
- Answers :12
(True or False) Sort orthogonality 1 and sort orthogonality 2 implies compositional
orthogonality. - Answers :True
C/C++ has 2 pointer operators, which operator will return the address of variable? -
Answers :Ampersand (&)
Multiple pointers can reference the same object. - Answers :True
Given the following code
char *p = "hello", *s = "this is a string";
strcpy(p, s);
printf("%s\n", p);
What will happen? - Answers :A run time error may occur at this line: strcpy(p, s);