NEW
Font size
WorksheetsQuiz 5 Review
Total questions: 22
Worksheet time: 13mins
What will the result of DIVIDE(9 + 6, 3) be if DIVIDE is defined as follows?
#define DIVIDE(A, B) A / B
2
5
11
DIVIDE(9 + 6, 3) would cause a compiler error.
What will the following code print
#define FOO -3
#if FOO
printf("Oranges ");
#else
printf("Bananas ");
#endif
Oranges
Bananas
Oranges Bananas
This code will not compile
What lines of code will prevent contents of header file "stuff" from being included more than once?
#ifdef STUFF_H
#define STUFF_H
#endif
Contents of stuff.h
#ifndef STUFF_H
#define STUFF_H
#endif
Contents of stuff.h
#ifdef STUFF_H
#define STUFF_H
Contents of stuff.h
#endif
#ifndef STUFF_H
#define STUFF_H
Contents of stuff.h
#endif
What will the following code print?
char myChar = 'A';
printf("%d", myChar);
'A'
The ASCII value of A
The address of 'A'
This code will cause a compiler error.
What will the following code print?
int a = 0x22;
a += 7
printf("%d", a);
29
0x29
41
It will not compile
What will the following code print?
int gpa =4;
gpa <<= 1;
gpa = gpa ^ (gpa - 4);
printf("%d", gpa);
0
4
8
12
(T/F) If we had an integer a, ++a and a++ are functionally identical.
True
False
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);
scanf("%d", num");
scanf("%d", &num);
scanf("%i", num);
scanf("%i", &num);
Where in memory are global variables stored?
The global data section
The stack
The heap
In the same space as the program text
Which LC3 assembly code mimics the following C code:
while (R1 >= 0) {
R1--;
}
BRn END
WHILE
ADD R1 R1 -1
BR WHILE
END
WHILE
BRzp END
ADD R1 R1 -1
BR WHILE
END
WHILE
BRn END
ADD R1 R1 -1
BR WHILE
END
Which C code does the following assembly mimic?
ADD R2, R1, -3.
BRnp ELSEIF
;; code here
BR END
ELSEIF BRzp END
;; code here
END
if (R1 == 3) {
//code here
} else if (R1 < 3) {
//code here
}
if (R1 == 3) {
//code here
} else {
//code here
}
if (R1 == 3) {
//code here
} else if (R1 == -1) {
//code here
}
if (R1 < 3) {
//code here
} else if (R1 >= 0) {
//code here
}
How can we create a pointer to an int variable, x, in C?
int ptr = &x;
int *ptr = x;
int *ptr = &x;
int ptr = *x;
What will the following code print out?
int a = 6;
int *ptr = &a;
*ptr = 7;
printf("%d %d\n", *ptr, a);
6 7
6 6
7 6
7 7
What will the following C code print?
printf("%d", sizeof(int));
4
8
32
Can't say
How can we get the value at index 2 of arr using pointers?
int arr[3] = {1, 2, 3};
(arr + 2)
&(arr + 2)
*arr + 2
*(arr + 2)
The following C code is valid:
int arr[5] = {5, 4, 3, 2, 1};
arr++;
printf("%d", arr[0]);
True
False
What does the following C code print out?
double arr[10];
printf("%d", sizeof(arr));
The size of a double in bytes
The size of a double pointer in bytes
The size of the entire array in bytes
What is a correct way to allocate space for an array of 10 integers?
int arr = malloc(10) *sizeof(int)
int *arr = malloc(10*8)
int *arr = (int *)
malloc(10*sizeof(int))
void arr = malloc(10*sizeof(int))
What is the primary purpose of free() in C?
To allocate space in memory for new variables
To check if memory allocation was successful
To deallocate memory that was previously allocated by malloc, calloc, and realloc
To put zeros in some part of memory
Do structs in C have the same functionality as classes in Java?
True
False
What is a correct way to assign "Gal" to a person's name attribute?
headTA -> name = "Gal"
strcpy(headTA.name, "Gal");
headTA.name = "Gal"
None of the above
Which of the following is a valid use case for typedef?
To include an external library
To make struct creation easier. Don't need to use "struct" for variable declaration
To specify the size of struct in memory
To create a pointer to a struct
