CSE 240 Midterm Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

A data type is defined by (Select all answers that apply)

the values allowed. the operations allowed.

Consider the following snippet of code: int main(){ char arr[3][3] = { { '0', '1', '2' }, { '3', '4', '5' }, { '6', '7', '\0' } }; char* base = &arr[0][0], *a = &arr[0][0]; a = base + 5; printf("*a = %c ", *a); a = base + 3; printf("row = %s", a); // Q5 return 0; } What is the entire output of the program after Q5 executes?

*a = 5 row = 34567

A pointer variable can take the address of a memory location as its value. Read the given program.

The output of the 1st printf statement is 80 The output of the 2nd printf statement is 60 .The output of the 3rd printf statement is 10

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

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

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

True

Multiple pointers can reference (point to) the same objects.

True

Java uses which of the following program processing?

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

When will the buffer be created?

When the file operation fopen is performed.

Consider the following snippet of C code: int main(){ int x = 5, y = 1, z = 3; int *a, *b, *c; a = &x; b = &y; c = &z; *a = *c; c = b; *c = 10; printf("x = %d y = %d\n", x, y); return 0;} What value is printed at line Q2?

X=3 Y=10

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 and A

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

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.

A final method in Java defines

an in-line function.

If we want to store an array of structures into a disk file, what file type should we choose?

binary file

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

bool

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

Amazon's shopping recommendation list is based on

data related to the buyers' behaviors

What parameters are required when performing file operations fread and fwrite? Select all that apply

destination source item size number of items

In C, what function can be used for inputting a string containing spaces?

fgets();

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;

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

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

input leaves a character in the file buffer.

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

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.

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

more than 26

Converting an integer value 5 to a float number 5.0 takes

more than two machine instruction.

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;

What data types in C have the same data range, assuming that the computer used is a 32-bit computer?

pointer type and unsigned int

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

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?

scanf("%s", &contactbook.name);

The tail variable in an array of structures is used for indicating (Select all that apply)

the starting address of the array. where to insert a new item, if the items in the array do not need to be sorted.

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

to allow a function to return different types of values

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

Contextual

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

#include <stdio.h> #define func(x, y) (x > y) ? y : x int main(){ int x = 10; int y = 9; int z = func(++x, y++); }

11

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

12

Consider the following snippet of code: int main(){ int arr[5] = { 0, 1, 2, 3, 4 }; int *a = &arr[4]; while (*a != 0){ printf("%d ", *a); a--; } printf("\n"); return 0; } What values are printed at the end of the program?

4 3 2 1

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

Read the snippet of C code below: int main() { int x = 5, y = 1, z = 3; // Variables of type int int* a, *b, *c; // Pointers to int of type int* a = &x; b = &y; b = a; printf("%d", *b); // Q1 return 0;} What value will be printed at line Q1?

5

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

7

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

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 compilation error will occur at this line: char *p = &a[0][0];

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

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 run time error will occur at the printf line.

Why do we need to flush the input buffer?

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

Explicit type conversion is commonly refer to as

Casting

Implicit type conversion is commonly refer to as

Coercion

If your application is composed of multiple modules (programs), which of the following program processing would you recommend?

Compilation

What does the | (pipe) symbol in a BNF rule mean?

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

The forward declaration of a function requires: (Select all answers that apply)

Return Type Parameter types function name

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?

Semantics Error


Kaugnay na mga set ng pag-aaral

Economics- Chapter 21- Protectionism

View Set

CSET S1 (World History Constructed Response)

View Set

Peptic Ulcers and GERD Chapter 37

View Set