wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz 5 Review

Total questions: 22

Worksheet time: 13mins

Name
Class
Date
1.

What will the result of DIVIDE(9 + 6, 3) be if DIVIDE is defined as follows?

#define DIVIDE(A, B) A / B

a)

2

b)

5

c)

11

d)

DIVIDE(9 + 6, 3) would cause a compiler error.

2.

What will the following code print

#define FOO -3

#if FOO

printf("Oranges ");

#else

printf("Bananas ");

#endif

a)

Oranges

b)

Bananas

c)

Oranges Bananas

d)

This code will not compile

3.

What lines of code will prevent contents of header file "stuff" from being included more than once?

a)

#ifdef STUFF_H​

#define STUFF_H ​

#endif

Contents of stuff.h​

b)

#ifndef STUFF_H​

#define STUFF_H ​

#endif

Contents of stuff.h​

c)

#ifdef STUFF_H​

#define STUFF_H ​

Contents of stuff.h​

#endif

d)

#ifndef STUFF_H​

#define STUFF_H ​

Contents of stuff.h​

#endif

4.

What will the following code print?

char myChar = 'A';

printf("%d", myChar);

a)

'A'

b)

The ASCII value of A

c)

The address of 'A'

d)

This code will cause a compiler error.

5.

What will the following code print?

int a = 0x22;

a += 7

printf("%d", a);

a)

29

b)

0x29

c)

41

d)

It will not compile

6.

What will the following code print?

int gpa =4;

gpa <<= 1;

gpa = gpa ^ (gpa - 4);

printf("%d", gpa);

a)

0

b)

4

c)

8

d)

12

7.

(T/F) If we had an integer a, ++a and a++ are functionally identical.

a)

True

b)

False

8.

What line should be placed here so that num is updated with user input?

int num;

printf("Enter a number: ");

// FILL IN LINE HERE

printf("You entered: %d\n", num);

a)

scanf("%d", num");

b)

scanf("%d", &num);

c)

scanf("%i", num);

d)

scanf("%i", &num);

9.

Where in memory are global variables stored?

a)

The global data section

b)

The stack

c)

The heap

d)

In the same space as the program text

10.

Which LC3 assembly code mimics the following C code:

while (R1 >= 0) {

R1--;

}

a)

BRn END

WHILE

ADD R1 R1 -1

BR WHILE

END

b)

WHILE

BRzp END

ADD R1 R1 -1

BR WHILE

END

c)

WHILE

BRn END

ADD R1 R1 -1

BR WHILE

END

11.

Which C code does the following assembly mimic?

ADD R2, R1, -3.

BRnp ELSEIF

;; code here

BR END

ELSEIF BRzp END

;; code here

END

a)

if (R1 == 3) {

//code here

} else if (R1 < 3) {

//code here

}

b)

if (R1 == 3) {

//code here

} else {

//code here

}

c)

if (R1 == 3) {

//code here

} else if (R1 == -1) {

//code here

}

d)

if (R1 < 3) {

//code here

} else if (R1 >= 0) {

//code here

}

12.

How can we create a pointer to an int variable, x, in C?

a)

int ptr = &x;

b)

int *ptr = x;

c)

int *ptr = &x;

d)

int ptr = *x;

13.

What will the following code print out?

int a = 6;

int *ptr = &a;

*ptr = 7;

printf("%d %d\n", *ptr, a);

a)

6 7

b)

6 6

c)

7 6

d)

7 7

14.

What will the following C code print?
printf("%d", sizeof(int));

a)

4

b)

8

c)

32

d)

Can't say

15.

How can we get the value at index 2 of arr using pointers?

int arr[3] = {1, 2, 3};

a)

(arr + 2)

b)

&(arr + 2)

c)

*arr + 2

d)

*(arr + 2)

16.

The following C code is valid:

int arr[5] = {5, 4, 3, 2, 1};

arr++;

printf("%d", arr[0]);

a)

True

b)

False

17.

What does the following C code print out?

double arr[10];
printf("%d", sizeof(arr));

a)

The size of a double in bytes

b)

The size of a double pointer in bytes

c)

The size of the entire array in bytes

18.

What is a correct way to allocate space for an array of 10 integers?

a)

int arr = malloc(10) *sizeof(int)

b)

int *arr = malloc(10*8)

c)

int *arr = (int *)

malloc(10*sizeof(int))

d)

void arr = malloc(10*sizeof(int))

19.

What is the primary purpose of free() in C?

a)

To allocate space in memory for new variables

b)

To check if memory allocation was successful

c)

To deallocate memory that was previously allocated by malloc, calloc, and realloc

d)

To put zeros in some part of memory

20.

Do structs in C have the same functionality as classes in Java?

a)

True

b)

False

21.

What is a correct way to assign "Gal" to a person's name attribute?

a)

headTA -> name = "Gal"

b)

strcpy(headTA.name, "Gal");

c)

headTA.name = "Gal"

d)

None of the above

22.

Which of the following is a valid use case for typedef?

a)

To include an external library

b)

To make struct creation easier. Don't need to use "struct" for variable declaration

c)

To specify the size of struct in memory

d)

To create a pointer to a struct