What is a structure or struct in C? Explain. - ANSWERS-Allows for
multiple data types under one variable defined by user.
What is an input validation loop? - ANSWERS-A loop that stops when
it is equal to something example: while(input != valid).
What is a C string? - ANSWERS-An array of characters ended by the
NULL character.
A(n) __________ is a variable that stores as its contents the address of
another variable. - ANSWERS-Pointer
A loop that executes "forever" is known as a(n)________ loop. -
ANSWERS-infinite
A(n) ___________ loop is a pattern in which the number of loop
repetitions is generally not known before loop execution. The condition
relies on a special value to terminate the loop. - ANSWERS-input
validation loop
END OF
PAGE
1
, CPTS 121 EXAM 2 LATEST
The act of joining two strings is called __________. The string library
function that performs the joining is called ______________. -
ANSWERS-String cat and strcat
A(n) _______ structure is a way of storing and organizing information.
An array is an example of one of these. - ANSWERS-data
The dereference or indirection operator is represented by the ________
symbol or character in C. - ANSWERS-*sum = i + j
True / False: Evaluating the expression strcmp("dog", "Dog") results in
the value 0 returned from strcmp (). - ANSWERS-False
True / False: An input validation loop is a pattern which is used to repeat
statements as long as a user entered value is not within a valid range. A
do-while loop is best suited for this pattern. - ANSWERS-True
True / False: array[index] is equivalent to (array + index). - ANSWERS-
False
END OF
PAGE
2
, CPTS 121 EXAM 2 LATEST
Answer the following questions based on the array declaration below:
char vehicle[20] = "porsche", my_candy[5] = "twix"; - ANSWERS-
Below
a.The value of strlen(vehicle) is _________ - ANSWERS-7
b. The contents of my_candy[4] is - ANSWERS-\0\
c. The value of strcmp (vehicle, "dodge") is: negative, positive, or zero?
- ANSWERS-positive
d. The contents of my_candy after the call strncpy(my_candy, vehicle,
2) is - ANSWERS-park
e. The contents of vehicle[3] after the call strcat (vehicle,
&my_candy[2]) is: - ANSWERS-'s'
(8 pts) Write a function called sum_squares () that accepts an integer n
as an argument, and returns the sum of the squares of each number
between 1 to n, inclusive: i.e. 1^2 + 2^2 + 3^2 + 4^2 + ... + (n - 1)^2 +
n^2. Precondition: n must be greater than or equal to 1. - ANSWERS-int
sum_squares(int n) {
END OF
PAGE
3