CS 270 Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What operator symbol in C performs a logical NOT.

!

The beginning character of a preprocessor directive is a/an

# (pound sign)

To include a header file that you have created, calculate.h, in your program, the following preprocessor directive should appear at the beginning of your program.

#include "calculate.h"

To include a header file that you have created, utils.h, in your program, the following preprocessor directive should appear at the beginning of your program.

#include "utils.h"

The translator that first examines the entire high-level language program before producing any machine language code is called a/an?

Compiler

What are valid types of cache misses that are not affected by varying the associativity of a cache?

Compulsory Misses Capacity Misses

Select the ways computing speed/capability can continue to increase in the face of end of the end of Dennard scaling and a slowing Moore's law. (Note: More than one option might be correct)

Utilize special IP blocks to do specific tasks like compression or security Offload some calculations to GPUs/Accelerators Increase the number of cores

What is the output format of the first and second printf statements after executing the following code segment? (Assume the standard I/O library's header file has already been included.) #define VALUE 11 int input; scanf("%d", &input); printf("%x\n", VALUE); printf("%c\n", input); a. b. c. d.

VALUE will be a hexadecimal number and input will be a character.

The expression on which a switch decision is based CANNOT be

a double

When the fopen call is successful it returns

a file pointer to a FILE struct

In the following C construct, the action statement will only be executed if the condition component evaluates to if (condition) action;

a nonzero value

int a[] = {3,4,5}; int *aptr; For the above statement the following is/are legal: When a pointer is incremented by one, the result is computed as New address = Old address + (Size of data type) A pointer and an array differ when declared, because memory is always set aside for an array, whereas for a pointer no memory is set aside.

aptr = aptr + 1, True, False

char array[20] = "School is fun!"; char *aptr; Which of the following would change the '!' to a '?' in array

aptr = array; *(aptr + 13) = '?';

After learning about caches we can say that accessing items sequentially from an _______ is fastest, this is due to _______ .

array, spacial locality

A ________ or ________ is the unit of data transferred between cache, memory and the processor. A common size for a block is ____ _______ .

block, cache line, 64 bytes

Which of the following is the correct way, in C, to declare a variable that holds a character and initialize it to G?

char letter = 'G'

Consider the following code: #define CHARGE_2 5 #define RADIUS 3 const float epsilon = 8.854E-19; main() { float k = 0; float charge_1 = 2.0; float force; k = 1 / (4 * 3.14159 * epsilon); force = (k * charge_1 * CHARGE_2) / (RADIUS * RADIUS); printf("The Coulomb force is: %f\n", force); } Which of the following is a value that can be change during the execution of the program?

charge_1

Given an algorithm X with a lower big 0 bound but poor cache locality vs an algorithm Y with a higher big O bound and good cache locality, at a specific problem size which algorithm will be the fastest.

could vary based on the specific problem size

Consider the following code: int *foo (){ i nt x= 10; return (&x); } int *bar (){ int * px; *px= 10; return px; } int *baz (){ int *px; px = (int *) malloc (sizeof(int)); *px= 10; return px; } Which function returns a pointer to a memory location that becomes invalid after the function returns? Which function dereferences an uninitialized pointer? Which function correctly returns a pointer to an int containing the value 10?

foo(), bar(), baz()

Some memory was allocated using the statement biz = (Zim*) malloc(2*sizeof(Zim)); We can free this memory using the statement

free(biz);

Consider the following code: typedef struct cat{ int **dog; int *y; }cat_t; int main() { struct cat *c = malloc(1 * sizeof(cat_t)); c->dog = malloc(34 * sizeof(int*)); // free memory here } What statements need to be added to free all allocated memory?

free(c->dog); free(c);

The region of main memory where memory is allocated dynamically is called the

heap

Here is a code segment int x =1, y =2, z[10]; int *ip; ip = &x; y = *ip; *ip = 0; ip = &z[0]; What can we say about ip and x at this point?

ip now points to z[0] and x is currently 0.

Increasing the ratio of hits in L1 cache to overall memory accesses __________ . All else being equal increasing this ratio would have the effect of ____________, and _________

is a desirable outcome of a cache design reducing the number of accesses from L2 cache decreasing the average memory access time

The #define preprocessor directive is used to provide the compiler with

macro substitutions

If an allocation with malloc fails then

malloc returns NULL

The fprintf command has one additional parameter not found in printf, this parameter takes a fprintf can be used to write formatted data to a file or to stdout

pointer to a FILE, True

The correct syntax to assign a value to a pointer variable is:

ptr=&x;

Fill in the blanks.In C the local variables are defined only within their _____ while the global variables are always available. Local variables are stored _________, global variables are stored ________.

scopes on the runtime stack in the data segment

printf is equivalent to calling fprintf using _______ as the file pointer

stdout

In C, using the special character sequence \t in a printf statement causes a _________ character to be printed out.

tab

After using the free function for a given node:

the memory is released for other usage

The components involved in the compilation process, listed in the order that they are used, are

the preprocessor, the compiler, and the linker.

Consider the following code: int * ptr; int i = 5; *ptr = i; What will *ptr equal after this code;

the statement *ptr = i; dereferences an uninitialized pointer and may cause a segmentation fault

To keep track of data used within a C program, the compiler needs all the following information EXCEPT

the variable's initial value

The following command would define Number to have the same meaning as int using typedef:

typedef int Number

On a write-through cache _________ refers to not fetching the missing block from memory before writing the updated value for the block to memory. This behavior would not be helpful if the code that is accessing the memory locations found in the block __________________

write around, is doing a mixture of reads and writes

If we want to keep identical data in memory and cache at all times we would want to implement a [1] cache.

write-through

Here is a code segment int x =1, y =3, z[8]; int *ip; ip = &y; x = *ip; What is the value of x at this point?

x is now 3

What is the value of x and y after these instructions?x = 3;y = --x+1;

x=2, y=3

What is the output of the following C statement? printf("x%x", 15);

xf

Here is a code segment int x =1, y =2, z[10]; int *ip; ip = &x; y = *ip; What is the value of y at this point?

y is now 1.

We want to allocate enough memory for an 5 element array, where each element of the array is of type double. We can do that by using a statement like this

zib = (double *) malloc(5*sizeof(double)); where zib points to a variable of the type double

We want to allocate enough memory for an 11 element array, where each element of the array is of type float. We can do that by using a statement like this ...

zib = (float *) malloc(11*sizeof(float)); where zib points to a variable of the type float

What operator symbol in C performs a bit-wise OR

|

Put the following C operators in precedence order from highest (1) to lowest (4) precedence.

*, +, ==, =

The ____ operator accesses members of a structure using a pointer.

-->

The value of y will be what after the following C code segment is executed. int x = 7; int y; y = x ^ x;

0

char array[20] = "School is fun!"; What is the integer value of array[18]?

0

What is the output for the following code? for (int i=0; i<10; i++) { if (i>5) { break; } printf("%d ", i); }

0 1 2 3 4 5

A C program has at least how many functions?

1

In C, what is the minimum number of iterations that a do-while loop will perform?

1

Consider the following code: 1 | main() 2 | { 3 | int w = 1; 4 | int x = 6; 5 | int y = 5; 6 | int z = 0; 7 | 8 | z = !z || !x && !y; 9 | z = x-- == y + 1; 10| z = (x / y++) * z + (x % w); 11| z = (x++ < (--y + w)) ? 10 : z; 1 2| z += z; 13| } After line 8 is executed, z will equal__ After line 9 is executed, z will equal__ After line 10 is executed, z will equal__ After line 11 is executed, z will equal__ After line 12 is executed, w will equal __ and x will equal __

1 1 1 10 1,6

Given a workload that consists of summing all the values in a large array into one variable, rank the following cache types by how long the operation would take. Lower is faster. Write-Back Write-Through with large write buffer Write-Through with small write buffer Write-Through with no write buffer

1, 2, 3, 4

Consider the following code: (1) #include <stdio.h> (2) (3) main() (4) { (5) int x, i; (6) char alpha; (7) (8) for (i = 0; i < 2; i++){ (9) for (x = 5; x > 0; x--); (10) alpha = a; (11) do (12) printf("%c",alpha++); (13) while (alpha <= 'z') (14) } (15) } The first syntax error occurs on line ____ . The second syntax error occurs on line ___ .

10, 13

The body of the while statement in the following C code segment will execute exactly twice. int x = 2; while (x != 0); x--;

False

To use type FILE requires including the string.h header file

False

The '.' operator may be substituted for the -> operator. malloc returns a block of memory initialized to 0.

False, False

Match the following terms to their definitions Precedence Associativity Statement Expression

In which order are operators evaluated? In which order are operators of the same precedence evaluated? Expresses a complete unit of work to be carried out by the computer. A valid combination of variables, literal values, and operators that produce a value..

Match the terms to their definitions. Compulsory miss Conflict miss Tag Associativity

Miss due to cache line requested address is part of being accessed for the first time Miss due to cache line requested address is part of being ejected from cache previously due to another request mapping to the same cache line Bits required to specify what memory locations are stored in a particular cache line The number of locations in cache a particular memory location can be shared

What is the type of error that exists in the following C program, which is supposed to output the sum of positive integers from 1 to 10? #include <stdio.h> main() { int result = 0; int i; for (i = 1; i <= 10; i++); result = result + i; printf("%d\n", result); }

Semantic Error

Over the last ~40 years memory performance has increased __________ than processor performance. During this same period bandwidth has improved at a _________rate than latency.

Slower|Faster

Which of the following errors are detected at compile time?

Syntactic Errors

Match the definition to the correct term Items accessed recently are likely to be accessed again soon. Items near those accessed recently are likely to be accessed soon

Temporal Locality, Spatial Locality

A C program starts with these two lines #include <stdio.h># define MAX 25 What do they do?

The first one includes a header file that provides standard library I/O functions, and the second line states that MAX everywhere stands for number 25.

Comparing the cache memory and the main memory, ..

The main memory cost per bit is much lower and the access time is much higher.

The range of values that an int variable always represents is

The range of values depends on the ISA of the computer.

One advantage of choosing interpretation instead of compilation is

There is no advantage of choosing interpretation, which is why most real-world software is produced using compiled languages.

If you write a whole C program all on one line with variable spacing between syntactic elements, it will still compile and execute correctly if you use proper C syntax.

True

In C, the name of an array evaluates to the address of its first element.

True

In C, the newline character is considered white space when reading input.

True

It is always possible to convert an if-else statement into a switch statement

True

The C statement scanf("%d", &time); reads in an entity, treats it as a decimal number, and stores the decimal number in variable time.

True

The condition in the following if statement is always false. if ( !(x = 3 ) )

True

The condition in the following if statement is always true. if ( x = 6 )

True

The semantics of a programming language specify how the properly formed code behaves.

True

When declaring an array, the size of the array always needs to be defined at compile time.

True

after this statement: typedef struct carType Car; Car is another name for struct carType

True

char string[15]; char *sptr; sptr = string; sptr contains the address of string[0].

True

*&X == X always evaluates to 1 ________ &*X == X always evaluates to 1 ________

True, False

Consider the following code: #include <stdio.h> #include <stdlib.h> void foo(int**x, int size){ *x = calloc(size, sizeof(int)); **x = 15; *(*x + 2) = 3;} int main(){ int a[] = {5, 9, 4, 6}; int *v = &a[ 0 ]; foo(&v, 4); printf("%d\n", v[ 0 ]); // part 1 printf("%d\n", v[ 1 ]); // part 2 printf("%d\n", v[ 2 ]); // part 3return 1;} What is the output for part 1 What is the output for part 2 What is the output for part 3

15, 0, 3

Consider the following code: char name[ 100 ]; int a; float b; scanf ("%d %f %s", &a, &b, name); If the data typed in is 20 150.25 motor the above scanf statement will return a value of __ If the data typed in is 20 motor 150.25 the above scanf statement will return a value of 3. ________ The following is/are true of the above command: ____________________________

3, False, & is not used before name because it is an array and is automatically passed by reference in C

What is the value of x after the following C statement. int x = 5 < 2 ? 7 : 42;

42

After the following C code segment is executed, what will the value of x be? int x; x = 5.86;

5

What is the output for the following code? for (int j=0; j<10; j++) { if (j<6) { continue; } printf("%d ", j); }

6 7 8 9

Here is a C structure: typedef struct point { int x; int y; } Point; We declare a local variable of type point. local is the first local variable. Point local; Which of the following LC-3 code sequences implements the following C statement: local.x = 3; Assume that fields like array elements are stored from lower memory to higher memory. Therefore the x field will be stored in an earlier address than the y field.

AND R1, R1, #0 ADD R1, R1, #3 STR R1, R5, #-1

When deleting the first element of a linked list one must: (multiple answers may apply)

Adjust the head pointer to point to the new beginning of the list Free the first element

In the translation process, the compiler (specifically the compiler not the overall mechanism of preprocessor, compiler, and linker sometimes refered to as the compiler) translates the source file into its corresponding machine code. The output of the compiler is called

An object module

After this program segment: double arr[20]; double *ptr; ptr = arr; What is equivalent to arr[5]?

*(ptr+5)

Assume we have the following array declaration: int a[5]; If we were implementing this array in LC-3, the if a[0] was stored at address 0x3500, then where would a[3] be stored?

0x3503

In the figure above the memory accesses labeled A most likely correspond to memory accesses related to _______ . During the first half of the shaded time period (delta t) what type(s) of locality is represented by the accesses? ________

Data, temporal

A missing semicolon at the end of a statement in a C program is a semantic error.

False

All C functions must take at least one input parameter.

False

Every implementation of C for every ISA requires an int to be 32 bits.

False

In C we can have at most one pointer pointing to any variable.

False

In C, functions can have two return values.

False


Set pelajaran terkait

Psychology Chapter 13, Psychology Chapter 12, Psychology Chapter 11, Psychology Chapter 14

View Set

ThePoint Questions Chapter 14 Maternity and Pediatric Nursing

View Set

Immunology- Major Histocompatibility Complex (MHC)

View Set

Target Marketing and Market Segmentation

View Set

Italian (Checkpoint B) - Vocabulary

View Set