1. Which of the following is TRUE regarding arrays? [A]The name of

1. Which of the following is TRUE regarding arrays?
[A] The name of the array represents the first value in the array.
[B] The name of the array represents all values found in the array.
[C] The name of the array represents where it is located in the memory of the computer.
[D] None of the above.
Use the function below for problem #2
int getData(int d[])
{
int ct = 0;
do
{
printf("Enter data #%d or -1 to exit: ", ct + 1);
scanf("%d", &d[ct]);
ct++;
}while(ct < MAXSIZE && d[ct - 1] > -1);
//MISSING RETURN STATEMENT GOES HERE
}
2. Which of the following represents the number of non-negative integers entered by the user from the function
above (MAXSIZE represents the defined size of the array)?
[A] The value of the variable ct should always be returned.
[B] The value of the expression ct – 1 should always be returned.
[C] The value of the expression ct – 1 should only been returned when the -1 value has been input by the
user.
[D] None of the above.
Use the function below for problem #3
void changeArray(int x[])
{
int temp;
int i;
}
for(i = 0; i < SIZE; i++)
{
temp = x[i];
x[i] = x[SIZE - 1 - i];
x[SIZE - 1 - i] = temp;
}
3. Which of the following describes the result of the function provided on the left (where SIZE is the defined
size of the array)?
[A] The order of the elements in the array are reversed.
[B] The elements in the array are in the same order after the loop as they were before the loop.
[C] One element in the array has been identified to be exchanged similar to one pass through the selection
sorting algorithm.
[D] None of the above.
Use the code below for problem #4
#define SIZE 11
void addNum(int[]);
int main()
{
int x[11] = {3, 2, 5, 4, 11, 8, 9, 10, 7, 6, 1};
addNum(x);
printf("x[3] = %d\n", x[3]);
}
return(0);
void addNum(int x[])
{
int i;
}
for(i = 1; i < SIZE; i++)
{
x[i] = x[i] + x[i - 1];
}
4. Which of the following is the output produced by the code segment above?
[A] x[3] = 10
[B] x[3] = 14
[C] x[3] = 9
[D] None of the above.
Use the code below for problem #5
#define SIZE 7
void changeElement(int, int*);
int main()
{
int lcv;
int ary[SIZE] = {1};
for(lcv = 1; lcv < SIZE; lcv++)
{
changeElement(ary[lcv - 1], &ary[lcv]);
}
printf("ary[5] = %d\n", ary[5]);
}
return(0);
void changeElement(int x, int *y)
{
*y = 2 * x;
}
5. Which of the following is the output produced by the code segment above?
[A] ary[5] = 16
[C] ary[5] = 64
[B] ary[5] = 32
[D] None of the above.
Use the code below for problem #6
#include<stdio.h>
int main()
{
int array[5] = {5, 4, 3, 2, 1};
int i = 0;
while(i < 4)
{
array[i] = array[i] % array[i + 1];
i++;
}
return(0);
}
6. Which index in the array above represents a value that is different from all of the other elements?
[A] 4
[C] 2
[B] 3
[D] None of the above.
Use the array below for problems 7 – 8
int array[13] = {10, 12, 13, 14, 15, 16, 18, 20, 21, 23, 24, 25, 33};
7. Which of the following represents the values of the variable mid in the binary search algorithm when
applying that algorithm to seek the target value 24?
[A] 6, 9, 10
[C] 6, 10
[B] 6, 9, 11, 10
[D] None of the above.
8. Which of the following represents the values of the variable mid in the binary search algorithm when
applying that algorithm to seek the target value 11?
[A] 6, 2, 1
[C] 6, 2, 0, 1
[B] 6, 2, 0
[D] None of the above.
Use the array below for problem #19
int data[13] = {10, 10, 10, 14, 15, 16, 18, 20, 21, 23, 24, 25, 33};
9. Which of the following represents the
and the target value 10?
[A] Total number of comparisons
[B] Total number of comparisons
[C] Total number of comparisons
[D] None of the above.
number of comparisons output from lab #12 given the array above
required: 5
required: 6
required: 7
Use the array below for problem #10
int data[13] = {10, 10, 10, 14, 15, 16, 18, 20, 21, 21, 21, 25, 33};
10. Which of the following represents the number of comparisons output from lab #12 given the array above and
the target value 21?
[A] Total number of comparisons required: 5
[B] Total number of comparisons required: 6
[C] Total number of comparisons required: 7
[D] None of the above.
Use the array below for problem #11
int data[13] = {10, 5, 10, 8, 1, 1, 8, 8, 21, 21, 21, 5, 3};
11. Which of the following represents the number of comparisons output from lab #12 given the array above and
the target value 21?
[A] Total number of comparisons required: 3
[B] Total number of comparisons required: 11
[C] Total number of comparisons required: 13
[D] None of the above.
Given the following array:
int x[7] = {4, 6, 8, 2, 0, 5, 3};
And the array after two passes through one of the three sorting algorithms:
0
2
4
6
8
3
5
12. Which sorting algorithm has been applied?
[A] Selection Sort
[B] Insertion Sort
[C] Bubble Sort
[D] More than one of the above.
Given the following array:
int x[7] = {4, 6, 8, 2, 0, 5, 3};
And the array after two passes through one of the three sorting algorithms:
8
6
4
2
0
5
3
13. Which sorting algorithm has been applied?
[A] Selection Sort
[B] Insertion Sort
[C] Bubble Sort
[D] More than one of the above.
Given the following array:
int x[7] = {3, 5, 4, 6, 8, 7, 9};
And the array after two passes through one of the three sorting algorithms:
9
8
3
5
4
6
7
14. Which sorting algorithm has been applied?
[A] Selection Sort
[B] Insertion Sort
[C] Bubble Sort
[D] More than one of the above.
Given the following array:
int x[7] = {3, 5, 4, 6, 8, 7, 9};
And the array after two passes through one of the three sorting algorithms:
3
4
5
6
7
8
9
15. Which sorting algorithm has been applied?
[A] Selection Sort
[B] Insertion Sort
[C] Bubble Sort
[D] More than one of the above.
Given the following array:
int x[7] = {3, 5, 4, 6, 8, 7, 9};
And the array after two passes through one of the three sorting algorithms:
3
4
5
6
8
7
9
16. Which sorting algorithm has been applied?
[A] Selection Sort
[B] Insertion Sort
[C] Bubble Sort
[D] More than one of the above.
Use the program below for problems 17 – 18
#include<stdio.h>
#include<string.h>
int main()
{
char str1[30] = "Final Exam Thursday";
char str2[25];
strcpy(str2, str1);
printf("str2 length = %d\n", strlen(str2));
strcpy(str1, str2);
printf("str1 length = %d\n", strlen(str2));
}
return(0);
17. What is the output generated by the first print statement in the program above?
[A] str2 length = 19
[C] str2 length = 25
[B] str2 length = 20
[D] None of the above.
18. What is the output generated by the second print statement in the program above?
[A] str1 length = 19
[C] str1 length = 30
[B] str1 length = 25
[D] None of the above.
int
int
int
int
a = 3;
b;
*x;
*y;
Use the code segment below for problems 20 – 21
x = &a;
y = x;
*x = 1;
a = 5;
printf("*x = %3d
*y = %3d
a = %3d\n", *x, *y, a);
*y = %3d
a = %3d
x = &b;
b = 11;
printf("*x = %3d
b = %3d\n", *x, *y, a, b);
19. What is the output generated by the first print statement in the code segment above?
[A] *x =
1 *y =
1 a =
5
[B] *x =
5 *y =
1 a =
5
[C] *x =
5 *y =
5 a =
5
[D] None of the above.
20. What is the output generated by the second print statement in the code segment above?
[A] *x = 11 *y = 11 a =
5 b = 11
[B] *x = 11 *y =
5 a =
5 b = 11
[C] *x =
5 *y =
1 a =
5 b = 11
[D] None of the above.
21. Which of the following is result of using an incorrect placeholder in a printf function?
[A] The compiler will issue a warning.
[B] The results will be converted to meet the data type of the placeholder used similar to an explicit data
type conversion.
[C] The results will be converted to meet the data type of the placeholder used similar to an implicit data
type conversion.
[D] None of the above.
22. Which of the following statements is TRUE?
[A] Any function that utilizes pass by address must have a void return type.
[B] Any function that utilizes pass by address must use pass by address for all parameters.
[C] Both A and B.
[D] None of the above.
Use the code below for problem #23
int c = -1;
int d = 1;
int result;
result = d-- || ++c;
printf("c = %d d = %d\n", c, d);
23. Which of the following is the output of the print statement of the code above?
[A] c = 0 d = 0
[C] c = 0 d = -1
[B] c = -1 d = 0
[D] None of the above.
24. Which of the following logical expressions is the complement of the expression below?
a > b && a > c
[A] a > b || a > c
[B] a < b || a < c
[C] a <= b && a <= c
[D] None of the above.
25. Which of the following logical expressions is the complement of the expression below?
a != b || b != c || a != c
[A] a == b || b == c || a == c
[B] a != b && b != c && a != c
int x = 3;
int y = 2;
int z = 3;
[C] a == b && b == c && a == c
[D] None of the above.
Use the code below for problem #26
printf("Result #1 = %d\n", x <= 3 || y >= 2 && z != 3);
printf("Result #2 = %d\n", x <= 3 || (y >= 2 && z != 3));
printf("Result #3 = %d\n", (x <= 3 || y >= 2) && z != 3);
26. Which of the following is TRUE regarding the code segment above?
[A] All three results will generate the same value.
[B] Only results #1 and #3 will generate the same value.
[C] Only results #1 and #2 will generate the same value.
[D] None of the above.
Use the code below for problem #27
int a = 732;
int b = 81912;
if(a % b < 500)
{
a = 0;
}
else if(a % b > 700)
{
b = 0;
}
else
{
a = 0;
b = 0;
}
printf("a = %d b = %d\n", a, b);
27. Which of the following is the output of the code
segment above?
[A] a = 732 b = 0
[B] a = 0 b = 81912
[C] a = 0 b = 0
[D] None of the above.
Use the code below for problem #28
if(score >= MINA)
{
grade = 'A';
}
else if(score >= MINB && score < MINA)
{
grade = 'B';
}
else if(score >= MINC && score < MINB)
{
grade = 'C';
}
else if(score >= MIND && score < MINC)
{
grade = 'D';
}
else
{
grade = 'F';
}
28. Which of the following is TRUE regarding the if/else if/else construct above?
[A] The second condition in each of the else if's are complements of the first condition in the previous if
or else if and are unnecessary because only the statements associated with the first true condition are
executed in an if/else if/else construct.
[B] The second condition in each of the else if's are necessary because an if/else if/else construct will
continue to execute statements found within all true conditions in an if/else if/else construct.
[C] Both conditions of each else if are necessary because statements associated with a true condition could
potentially alter the values of variables used in later conditions in an if/else if/else construct.
[D] None of the above.
Use the code below for problem #29
int x = 3;
int y = 2;
int z = 1;
z = x - y - z ? x++ : ++y;
printf("x = %d y = %d z = %d\n", x, y, z);
29. Which of the following is the output of the code
segment above?
[A] x = 3 y = 3 z = 2
[B] x = 4 y = 3 z = 3
[C] x = 3 y = 3 z = 3
[D] None of the above.
Use the code below for problem #30
int month = 3;
int year = 2000;
int day = 2;
switch(month)
{
case 5: day
case 4: day
case 3: day
case 2: day
}
+=
+=
+=
+=
30;
31;
28 + ((!(year % 4) && (year % 100)) || !(year % 400));
31;
printf("day = %d\n", day);
30. What is the output produced by the code segment above?
[A] day = 62
[C] day = 60
[B] day = 61
[D] None of the above.
int main()
{
int x = 35;
int y = 7;
int z = -1;
Use the code below for problems 31 – 32
switch(x % y == 0)
{
case 0: z = 1;
break;
case 1: z = 0;
break;
}
printf("z = %d\n", z);
return(0);
}
31. Which of the following switch statement rules is being violated by the code segment above?
[A] The control expression must be integral.
[B] Each case label is the keyword case followed by a constant expression.
[C] No two case labels can have the same value.
[D] None of the above.
32. Which of the following is the output generated by the code segment above?
[A] z = -1
[C] z = 1
[B] z = 0
[D] None of the above.
33. Which of the following will result in an infinite loop? The variable used in each for loop has been declared
as an integer.
[A] for(i = 0; i != 100100; i += 10)
[C] for(i = 0; i < 85; i + 17)
[B] for(i = 0; i % 169 > 0; i = i + 13)
[D] None of the above.
Use the code below for problems 34 – 36
5
6
7
8
9
10
11
12
13
14
15
int y = 0;
int x = 34219;
do
{
y *= 10;
y += x % 10;
x /= 10;
}while(x > 0);
printf("y = %d\n", y);
34. Which of the following is the output generated by the code segment above?
[A] y = 19
[C] y = 9124
[B] y = 91243
[D] None of the above.
35. Which of the following is the output generated by the code segment above if line 10 was removed?
[A] y = 19
[C] y = 0
[B] y = 16
[D] None of the above.
36. Which of the following would NOT produce the same results as the original code above [replacing lines 8 –
13] given that the variable x will always be a non-negative integer?
[A]
[B]
[C]
while(x > 0)
for(x = 34219; x > 0; x /= 10) do
{
{
{
y *= 10;
y *= 10;
y *= 10;
y += x % 10;
y += x % 10;
y += x % 10;
x /= 10;
}
x /= 10;
}
}while(x != 0);
[D]
None of the above.
Use the code below for problems 37 – 39
int row;
int col;
int sz;
for(row = 0; row <= sz; row++)
{
for(col = 0; col <= sz; col++)
{
if(col == sz - row + 1)
{
printf("%d", sz);
}
else
{
printf("%c", '$');
}
}
printf("\n");
}
37. Given that the variable sz is assigned a value of 5, which of the following is the first line of output generated
by the code segment above?
[A] $$$$$$
[C] $$$$5$
[B] $$$$$5
[D] None of the above.
38. Given that the variable sz is assigned a value of 5, which of the following is the last line of output generated
by the code segment above?
[A] $$$$$$
[C] $5$$$$
[B] 5$$$$$
[D] None of the above.
39. Given that the variable sz is assigned a value of 5, what is the total number of characters ($ and 5) displayed
to the monitor?
[A] 30
[C] 25
[B] 36
[D] None of the above.
40. Which of the following is used to visually represent the algorithm of a single function?
[A] A Flowchart
[C] A Specification Chart
[B] A Structure Chart
[D] None of the above.
41. According to course standards, which of the following would never be given a global scope?
[A] Function prototypes.
[C] Variables.
[B] Function definitions.
[D] None of the above.
42. Which of the following is TRUE regarding scope?
[A] It is poor programming style to reuse identifiers within the same scope.
[B] It is poor programming style to reuse identifiers with non-overlapping scope.
[C] It is always poor programming style to reuse identifiers.
[D] None of the above.
43. Which of the following can be detected by the compiler?
[A] A reference to an array index value that exceeds the defined limits of the array.
[B] A loop control expression that will result in an infinite loop.
[C] A function call that includes fewer parameters than was specified in the function prototype.
[D] None of the above.
Use the code below for problems 44 – 46
int a = 7;
int b = 11;
int c;
float d = 4.85;
c = (float) (b / a);
printf("c = %d\n", c);
44. What is the first output generated by the code on
the left?
[A] c = 0
[B] c = 1
[C] c = 2
[D] None of the above.
c = a / (float) b + 0.5;
printf("c = %d\n", c);
c = (int) d / b + 0.5;
printf("c = %d\n", c);
45. What is the second output generated by the code above?
[A] c = 0
[C] c = 2
[B] c = 1
[D] None of the above.
46. What is the third output generated by the code above?
[A] c = 0
[B] c = 1
[C] c = 2
[D] None of the above.
47. Which of the following file functions utilizes the name of the external file being accessed rather than the
name of the file handle variable?
[A] fopen
[C] fclose
[B] fscanf
[D] Both A and C.
48. Which of the following is FALSE regarding the scanf function in the C programming language and the
fscanf function in MATLAB (or Octave)?
[A] The fscanf function in MATLAB (or Octave) has no address list similar to the scanf function in C.
[B] The fscanf function in MATLAB (or Octave) includes the name of the file handle variable to indicate the
source of the data.
[C] The format string in C's scanf function uses double quotes while the format string in MATLAB's fscanf
function uses single quotes.
[D] None of the above.
49. Which of the following is the result of attempting to redirect output from an executable (a.out) file to an
existing file?
[A] The existing file is over-written.
[B] The operating system reports an error that it cannot over-write an existing file.
[C] A new file with an additional character in its name is created to distinguish it from the existing file.
[D] None of the above.
50. What should you be sure to do when contacting the instructor regarding your course grade?
[A] Wait until minimums for each letter grade are announced.
[B] Be sure to use your Purdue e-mail address and state which course you were taking.
[C] Provide specific concerns you have with specific assignments as grades in the course will be based on
points earn and not factors external to the course.
[D] All of the above.
This page lists C operators in order of precedence (highest to lowest). Their associativity indicates in what
order operators of equal precedence in an expression are applied.
Operator
Description
Associativity
()
[]
.
->
++ --
Parentheses (function call) (see Note 1)
Brackets (array subscript)
Member selection via object name
Member selection via pointer
Postfix increment/decrement (see Note 2)
left-to-right
++ -+ ! ~
(type)
*
&
sizeof
Prefix increment/decrement
Unary plus/minus
Logical negation/bitwise complement
Cast (change type)
Dereference
Address
Determine size in bytes
right-to-left
* / %
Multiplication/division/modulus
left-to-right
+ -
Addition/subtraction
left-to-right
<< >>
Bitwise shift left, Bitwise shift right
left-to-right
< <=
> >=
Relational less than/less than or equal to
Relational greater than/greater than or equal to
left-to-right
== !=
Relational is equal to/is not equal to
left-to-right
&
Bitwise AND
left-to-right
^
Bitwise exclusive OR
left-to-right
|
Bitwise inclusive OR
left-to-right
&&
Logical AND
left-to-right
||
Logical OR
left-to-right
?:
Ternary conditional
right-to-left
=
+= -=
*= /=
%= &=
^= |=
<<= >>=
Assignment
Addition/subtraction assignment
Multiplication/division assignment
Modulus/bitwise AND assignment
Bitwise exclusive/inclusive OR assignment
Bitwise shift left/right assignment
right-to-left
Comma (separate expressions)
left-to-right
,
ASCII Table
Char Dec Char Dec Char Dec Char
(nul)
0 space 32
@
64
`
(soh)
1
!
33
A
65
a
(stx)
2
"
34
B
66
b
(etx)
3
#
35
C
67
c
(eot)
4
$
36
D
68
d
5
%
37
E
69
e
(enq)
6
&
38
F
70
f
(ack)
7
39
G
71
g
(bel)
8
(
40
H
72
h
(bs)
(ht)
9
)
41
I
73
i
10
*
42
J
74
j
(nl)
11
+
43
K
75
k
(vt)
12
,
44
L
76
l
(np)
13
45
M
77
m
(cr)
(so)
14
.
46
N
78
n
15
/
47
O
79
o
(si)
0
48
P
80
p
(dle) 16
(dc1) 17
1
49
Q
81
q
(dc2) 18
2
50
R
82
r
(dc3) 19
3
51
S
83
s
(dc4) 20
4
52
T
84
t
5
53
U
85
u
(nak) 21
(syn) 22
6
54
V
86
v
7
55
W
87
w
(etb) 23
(can) 24
8
56
X
88
x
(em) 25
9
57
Y
89
y
(sub) 26
:
58
Z
90
z
27
;
59
[
91
{
(esc)
28
<
60
\
92
|
(fs)
(gs)
29
=
61
]
93
}
(rs)
30
>
62
^
94
~
(us)
31
?
63
_
95 (del)
Dec
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Lab Time
Lab Day
Location and TA
Section
7:30
Tuesday
SC 189 – Jessica Sparks
2601
9:30
Tuesday
SC 189 – Sebastian Lee
1101
11:30
Tuesday
SC 189 – Amir Warsanah
1301
1:30
Tuesday
SC 189 – Nicki Schrank
2501
9:30
Wednesday
SC 189 – Kuan-Po Chen
1201
11:30
Wednesday
SC 189 – Caleb Bean
2401
1:30
Wednesday
SC 189 – Alyssa Welles
1601
7:30
Thursday
SC 189 – Ryne Rayburn
2201
9:30
Thursday
SC 289 – Xi Luo
1401
11:30
Thursday
SC 189 – Mike James
2301
1:30
Thursday
SC 189 – John Grabarczyk
2101