CSE240 Midterm Quizzes

Pataasin ang iyong marka sa homework at exams ngayon gamit ang 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 - the name stored in the terminal node in the linked list - the terminal node itself

- 0 - the address of a terminal node

Which of the following statements are correct if a language is strongly typed. Select all that apply. - Each name in a program has a single type associated with it. - Type is not known at compilation time. - Type errors are always reported. - The variable size can be determined at execution time.

- Each name in a program has a single type associated with it. - Type errors are always reported.

When will the buffer be created? a) When the pointer of a file type is declared b) When the file operation fopen is performed c) When the file operation fread or fwrite is performed d) When the file is closed

- When the file operation fopen is performed

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[0] - *a[0]

- a - &a[0]

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 orders of the members in the structure. - changing the computer from a 32-bit to a 64-bit processor - changing an int-type variable to a pointer-type variable

- 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

What parameters are required when performing file operations fread and fwrite? Select all that apply. - destination - source - item size - number of items - type of the file (binary or text)

- destination - source - item size - number of items

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

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

The forward declaration of a function requires: (Select all answers that apply) - return type - function name - parameter types - function implementation - initial address of the function code

- return type - function name - parameter types

A data type is defined by (Select all answers that apply) - the values allowed - the locations allowed - the addresses allowed - the operations allowed

- the values allowed - the operations allowed

In a given programming and execution environment, a variable declaration in C binds a name to a memory location. What else are also determined in declaration? Select all that apply. - variable type - variable scope - variable size (number of bytes) - the time period that the variable will be in a register of the computer

- variable type - variable scope - variable size (number of bytes)

The complexity of searching an arbitrary binary search tree with n nodes is the order of a) 0(1) b) 0(lg n) c) 0(n) d) 0(n*n)

0(n)

What is the time complexity of the insertion sort algorithm? a) 0(n) b) 0(n*n) c) 0(nlgn) d) 0(lgn)

0(n*n)

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? 2. What value will be printed for variable y?

1. 2 2. 3

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. 1. 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

1. 90 2. 70 3. 20

Given the following code, what is the expected value for z? #include <stdio.h> #define fun(x, y) (x > y) ? y: x int main(){ int x = 10; int y = 9; int z = func(++x, y++); } a) 9 b) 10 c) 11 d) 12

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; a) 10 b) 100 c) 1000 d) None of these values

10

Given a declaration: char a[] = "Hello World"; What is the size (in bytes) of the array a[]? a) 10 b) 11 c) 12 d) 44

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; a) 4 bytes b) 66 bytes c) 68 bytes d) 72 bytes

68 bytes

Which of the following statements is true? a) A global variable cannot be used as the actual parameter for call-by-alias b) A structure type of variable cannot be as the actual parameter for call-by-value c) A constant cannot be used as the actual parameter for call-by-address d) A constant cannot be used as the actual parameter for call-by-alias e) The return value of a function cannot be a pointer

A constant cannot be used as the actual parameter for call-by-alias

Given the following code char *p = "hello", *s = "this is a string"; strcpy(p, s); printf("%s\n", p); What will happen? a) It prints: hello b) It prints: this c) A compilation error will occur at this line: strcpy(p, s); d) A run time error may occur at this line: strcpy(p, s);

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

C/C++ has 2 pointer operators, which operator will return the address of a variable? a) Comma (,) b) Asterisk (*) c) Ampersand (&) d) Semicolon (:)

Ampersand (&)

Why do we need to flush the input buffer? a) An unformatted input can read the newline character left from the previous input operation b) There is no buffer used for unformatted input c) There is no buffer used for formatted input d) We never need to flush an input buffer

An unformatted input can read the newline character left from the previous input operation

When do we need to use fflush() or cin.ignore()? a) Between any two inputs b) Between a formatted input and an unformatted input c) Between two formatted inputs d) Between two unformatted inputs

Between a formatted input and an unformatted input

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, which the actual parameter in call-by-alias can be a variable or a constant

Call-by-alias involves one variable only, while call-by-address involves two variables

Explicit type conversion is commonly refer to as _____. a) Typing b) Coercion c) Casting d) Paradigm

Casting

Implicit type conversion is commonly refer to as ______. a) Typing b) Coercion c) Casting d) Paradigm

Coercion

The reason that we use a buffer between the disk and the memory is _____ a) Disk access speed is low, but large blocks of data can be read from and written to the disk b) Disk can store binary type of data only c) Disk can store text type of data only d) Memory is organized in a one-dimensional array and disk is organized in a multidimensional array

Disk access speed is low, but large blocks of data can be read from and written to the disk

If you like to see accurate debugging information, which of the following program processing would you recommend? a) Interpretation b) Compilation c) Both compilation and interpretation provide the same level of debugging information d) Some time compilation is better than interpretation, but other time interpretation is better than compilation.

Interpretation

What does the | (pipe) symbol in a BNF rule mean? a) It is a terminal symbol and will be in the final string b) It is an "or" operation. Choose one of the options. c) The concatenation of two adjacent terminal symbols. d) It indicates a comment in a BNF rule.

It is an "or" operation. Choose one of the options.

Given the following code char a[2][4] = {{'c', 'a', 'r', 'b'}, {'i', 'k', 'e', '\0'}}; char *p = &a[0][0]; while(*p != '\0'){ printf("%c", *p); p++; } What will happen? a) It prints: carb b) It prints: carbike c) A compilation error will occur at this line: char *p = &a[0][0]; d) A compilation error will occur at this line: while(*p != '\0')

It prints: carbike

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) It prints: cat b) It prints: dbu c) It prints: a string of random characters d) A run time error will occur at the printf line

It prints: dbu

Which language will report a compilation error for the following snippet of code? int i = 3; double n, j = 3.0; n = i + j; a) C b) C++ c) Java d) All of these languages

Java

What is the main reason of applying two-step translation of high level programming language? a) More accurate debugging information b) Better support of macros c) One compiler for all machines d) Support stronger typing system

One compiler for all machines

Macros-Processing in C takes place during which phase? a) Saving b) Pre-processing c) Compilation d) Execution

Pre-processing

If your program was designed to print "Hello World" ten (10) times, but during execution, it printed eleven (11) times. What type of error is it? a) Lexical Error b) Syntactic Error c) Contextual Error d) Semantics Error

Semantics Error

Given this snippet of code in C, char alpha = 'a'; float numeric = alpha + 10; which of the following statement is correct: a) Syntactically correct, but contextually incorrect b) Syntactically correct and contextually correct. c) Syntactically incorrect, but contextually correct. d) Syntactically incorrect and contextually incorrect.

Syntactically correct, but contextually incorrect.

What is the main problem with using an array of structures to store data records such as contact list? a) The total length of the list must be determined in advance b) The same data type hast to be used to store different types of information c) For each data element, additional memory has to be used to store the link to the next element d) struct type cannot be used to define array as the array's element type

The total length of the list must be determined in advance

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

True

A merge-sort is typically implemented using a) a tail-recursive function b) a function with a single recursive call c) a function with two recursive calls d) two while loops

a function with two recursive calls

When an item is deleted from Amazon's catalog list, we need to delete the FBT linked list using a) free(ftbHead); b) ftbHead = 0; c) a loop to free each node in the FTB list. d) free(ftbHead); ftbHead = 0;

a loop to free each node in the FTB list

In the memory hierarchy of a computer system, which type of memory is the fastest one? a) Registers b) Cache c) Main memory d) Secondary storage

a) Registers

Which of the following C assignment statement (assign a value to a variable at the semantic level) will NOT cause a compilation error? Assume the array has been declared as: char a[5]; a) a[] = {'h', 'i'}; b) a = "hi"; c) a[0] = 'h'; d) a = "h";

a[0] = 'h';

Given this snippet of codes, identify the passing mechanism used for x (in func). void func(int *x, int y){ *x = *x + y; y = 2; } a) call-by-value b) call-by-address c) call-by-reference d) call-by-name

call-by-address

Which parameter passing mechanism does not have side-effects? a) call-by-value b) call-by-address c) call-by-reference d) All of them have side-effects

call-by-value

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? a) const int size2 = 20; b) char a1[size1]; c) char a2[size2]; d) both char a1[size1] and char a2[size2];

char a2[size2];

In C, what function can be used for inputting a string containing spaces? a) scanf("%s", &str); b) fgets(); c) getchar(); d) scanf.getline(...);

fgets();

In the hanoi towers function, what part of the code represents step 4: Construction of size-n problem from size(n-1) problems? a) hanoitowers(n-1, S, D, M); b) if(n == 1) { printf("move top from %s to %s\n", S, D);} c) hanoitower(1, S, M, D); hanoitowers(n, S, D, M); d) hanoitowers(n-1, S, D, M); hanoitowers(1, S, M, D); hanoitowers(n-1, M, S, D);

hanoitowers(n-1, S, D, M); hanoitowers(1, S, M, D); hanoitowers(n-1, M, S, D);

The data stored in a binary search tree is sorted, if the tree is traversed in a) preorder b) postorder c) inorder d) in any order

inorder

Which implementation of a function has potentially the best performance in terms of execution speed? a) normal function b) macro c) inline function d) interpretation

macro

How many different identifiers can the following BNF ruleset generate? <char> ::= a | b | c | . . . | x | y | z <identifier> : : = <char> | <char> <identifier> ----- a) None b) 1 c) 26 d) More than 26

more than 26

Where is the main() function located in a C++ program? a) in the Main class b) in all classes c) in any one class d) outside any class

outside any class

Given the information below, how do you insert a 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; a) p->next = head; head = p; b) head = p; c) p->next = head; d) head = p; p->next = head;

p->next = head; head = p;

Given the declaration: char A[3] = {'C', 'a', 'r'}, *p = A; what statements prints character a? a) printf("%c", *p); b) printf("%c", *p + 1); c) printf("%c", *p++); d) printf("%c", *(++p));

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

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? a) scanf("%s", contactbook[tail].name); b) scanf("%s", &contactbook[tail].name); c) scanf("%s", contactbook.name); d) scanf("%s", &contactbook.name);

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

A critical step in writing a recursive function is to assume that the a) stopping condition can be identified by the underlying recursive mechanism b) size-1 problem has been solved by the underlying recursive mechanism c) size-m problem has been solved by the underlying recursive mechanism, where m < n d) size-n problem has been solved by the underlying recursive mechanism

size-m problem has been solved by the underlying recursive mechanism, where m < n

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; a) x = head; while(x != NULL){ printf("%s - %s", x->name, x->location); x = x->next; } b) x = head; while(x->next != NULL){ printf("%s - %s", x->name, x->location); x = x->next; } c) while(head != NULL){ printf("%s - %s", head->name, head->location); head = head->next; d) while(head->next != NULL){ printf("%s - %s", head->name, head->location); head = head->next; }

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

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

y a


Kaugnay na mga set ng pag-aaral

Chapter 1: Managing Effectively in a Changing World

View Set

Ch 9 Material Requirements Planning

View Set

CS week 6+7 (design)+ tables+forms

View Set

Ch. 19: Everyday Theology (THEO 104 LUO)

View Set