CSE 240 Midterm

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Assume that the search function of a linked list is specified by struct Terminal* search(); What values can the search function return? Select all correct answers.

0, the address of a terminal node

If you like to see accurate debugging information, which of the following program processing would you recommend?

Interpretation

ow many different identifiers can the following BNF ruleset generate? <char> ::= a | b | c | ... | x | y | z <identifier> ::= <char> | <char> <identifier>

More than 26.

What key feature of programming languages is supported by C++, but not Java?

Pointers

What programming languages better prepare you for leaning database query languages such as SQL and LINQ?

Prolog and Scheme

What is the major improvement of structured programming languages over the earlier programming languages?

Removing Goto statement from the language.

(True or False) Sort orthogonality 1 and sort orthogonality 2 implies compositional orthogonality.

True

Multiple pointers can reference the same object.

True

Java uses which of the following program processing?

Two Step Translation with Intermediate Code -- (Compilation + Interpretation)

Given a C declaration: char a[] = "Hello World"; What can be used as the initial address of array a[]? Select all correct answers.

a,&a[0]

A final method in Java defines:

an in-line function

Which of the following types is a C++ type, but NOT a C type?

bool

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; }

call-by-alias

In C++, what function can be used to input a string with spaces?

cin.getline(...);

During compilation, linker is used for

resolving external references (bring in code from other libraries).

Assume pointer variable p points to node x, and node x's next pointer points to node y. What does free(p) operation mean?

return the memory held by x to the free memory pool.

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.

Type checking happens during compilation phase, it reinforces which of the following structural layer?

Contextual

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++); }

10

Given this snippet of code, what is the value of x after executing the last statement? int x = 10, *y; y = &x; y = y + 1; *y = 100;

10

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;

100

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;

100

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;

4 bytes

Assume this is a 32-bit environment, given a declaration: int a[10]; What is the size (in bytes) of the entire array?

40

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

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

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); }

A macro

Given the following code char *p = "hello", *s = "this is a string"; strcpy(p, s); printf("%s\n", p); What will happen?

A run time error may occur at this line: strcpy(p, s);

What programming language characteristics impact the readability of the programs written in this language?

Control structures, Syntax design, and Data Structures

Which of the following coding practice can lead to a higher memory efficiency (use fewer padding bytes) in defining a structure?

Keep the character type variables together.

In contrast to Web 1.0, what is the key function of Web 2.0?

Web is the computing platform

The size (number of bytes) of a structure-type variable can be changed by the following factors. Select all that apply.

adding a member into the structure changing the computer from a 32-bit to a 64-bit processor. changing the orders of the members in the structure. adding a member into the structure.

The imperative programming paradigm is popular and is a part of object-oriented computing paradigm, because it ____ (Select all answers that apply).

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.

What computing paradigm can solve a problem by describing the requirements, without writing code in a step-wise fashion to solve the problem?

logic

Which implementation of a function has potentially the best performance in terms of execution speed?

macro

What is the maximum number of padding bytes that a compiler can add to a structure?

more than 4

Where is the main() function located in a C or C++ program?

outside any class

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;

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; }

call-by-value

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?

It prints: dbu

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;

None of the above (not 10, 100, or 1000)

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.

What is the main reason of applying two-step translation of high level programming language?

One compiler for all machines

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;

1000

Given a declaration: char a[] = "Hello World"; What is the size (in bytes) of the array a[]?

12

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;

68 bytes

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); }

9

C/C++ has 2 pointer operators, which operator will return the address of variable?

Ampersand (&)

When do we need to use fflush() or cin.ignore()?

Between a formatted input and an unformatted input

Explicit type conversion is commonly referred to as __________ .

Casting.

During data declaration, a name is binded to a memory location, what else can be identify as part of this process?

Data type, Scope, Qualifier

The reason that we use a buffer between the disk and the memory is

Disk access speed is low, and disk is read and written large block of data

What computing paradigm enforces stateless (no variable allowed) programming?

Functional

Which commands (constructs) do NOT have a loop when expressed in syntax graphs? Select all that apply

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:

Syntactically correct, but contextually incorrect.

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 printf statement } Answer the following three questions.

The output of the 1st printf statement is 90. The output of the 2nd printf statement is 70. The output of the 3rd printf statement is 20.

Given the C declaration: char s1[4], s2[ ] = "hello"; if a string copy function strcpy(s1, s2) is executed, what will happen?

The result is s1 will contain the string "hell", and the following two byte locations will contain 'o' an '\0'.

What is the main problem of using an array of structures to store data records such as contact list?

The total length of the list must be determined in advance.

Given the snippet of codes, identify the passing mechanism used for x (in function). void func(int *x, int y) { *x = *x + y; y = 2; }

call-by-address

When will the buffer be created?

When the file operation fopen is performed.

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,

a longer machine code but with shorter execution time.

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?

char a2[size2];

Event-driven computing paradigm is to:

define a set of events and write an event handler for each event

What parameters are required when performing file operations fread and fwrite?

destination number of items item size source

What is a feature of object-oriented computing?

encapsulation of states

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;

The reason that we need to call fflush() or cin.ignore() is because the previous...

input leaves a character in the file buffer.

Given the information below, which of the following snippet of codes will insert a new node in the second place in the linked-list. Assume the linked-list contains already at least one node. struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *head, *p, *q;

p = (struct contact *) malloc(sizeof(struct contact)); ... p->next = head->next; head->next = p;

Given the declaration: char A[3] = {'C', 'a', 'r'}, *p = A; what statement prints character a?

printf("%c", *(++p));

Given the declaration: char a[] = "Hello"; char *p = a, *q; what operations are valid syntactically? Select all that apply.

q = &(*p); and *q = *(&a[0]);

In the C-Style input function scanf("%d", &i); What does the character "&" mean?

scanf takes the address of an variable as its parameter.

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]; int tail = 0; Which statement can read a phone number into the phone field of the structure?

scanf("%d", &contactbook[tail].phone);

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]; int tail = 0; Which statement can read a name into the name field of the structure?

scanf("%s", contactbook[tail].name);

If a program contains an error that divides a number by zero at the execution time. This error is a

semantic error

Assume a variable is declared in a block of code within a pair of curly braces. The scope of the variable ______

starts from its declaration point and extends to the end of the block.

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);

What is NOT the purpose (functionality) of the forward declaration (prototype)?

to allow functions to return different types of values.

Given the information below, which of the following snippet of codes 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;

while(head->next != NULL) { printf("%s - %s", head->name, head->location); head = head->next; }

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); 1. What value will be printed for variable x? [x]. 2. What value will be printed for variable y? [y]

x = 6, y = 7

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 applies.) char array[] = "Hello Joe"; char *x;

x = array; *(x + 6) = 'D';

Given the information below, how will you access the name for a terminal node pointed to by x? struct Terminal { char name[30]; char location[32]; struct Terminal* next; } *x;

x->name;

Given the snippet of codes, what is the expected output? void func(int *x, int y) { *x = *x + y; x = 10; } void main() { int x = 10, y = 10; func(&x, y); printf("x: %d, y: %d", x, y); }

x: 20, y: 10

Given the snippet of codes, what is the expected output? void func(int *x, int y) { *x = *x + y; x = 10; } void main() { int x = 10, y = 10; func(&x, y); printf("x: %d, y: %d", x, y); }

x: 20, y: 10

Given the following snippet of code, answer the following two questions based on the code: typedef enum {red, amber, green} traffic_light; traffic_light x = red, y = green; while (x != y) { x++; } y++; printf("x = %d, y = %d", x, y); 1. What value will be printed for variable x? Please choose: [x]. 2. What value will be printed for variable y? Please choose: [y]

x= 2; y=3;

For the following BNF ruleset, which are terminal symbols? (Check all that apply.) <char> ::= a | b | c | ... | x | y | z <identifier> ::= <char> | <char> <identifier>

y, a


Ensembles d'études connexes

History of Film and TV (part #2)

View Set

Hist63 Midterm (European history)

View Set

chapter 21 physical science quiz

View Set

Orion Series 65 Exam 5 - Chapters 14-15-16-17

View Set

3.3.4 normal profits, supernormal profits and losses

View Set

English 104: College Composition RE-TAKE

View Set

NEMCC intro to philosophy midterm

View Set

Strategies for Success Full Review

View Set