x
x
INSTRUCTIONS TO STUDENTS
1. This review contains 12 practice questions. Please note that the num-
ber of questions in this review is NOT always the same to the number
of questions on the exam.
2. The questions on this review should not be interpreted as the precise
topics to be asked on the exams. Students are expected to review all
content that was presented in lecture.
3. Answer all questions to the best of your ability. Partial credit will be
given for attempts on questions. Make sure to write proper C Syntax
for the answers. Any incorrect syntax will cause points to be deducted.
Pay close attention to syntax and write clearly and neatly.
4. You do not need to write out all components of a working C
program (main function, preprocessor directives, etc...) un-
less specified otherwise in the questions.
Last Name:
First Name:
UCF ID:
COP 3223
Question 1
Consider the following lines of code: Consider the following code and partial
sample output.
1 int main ( void )
2 {
3 char phrase [10];
4 char phrase2 [10];
5 printf ( " Enter a phrase : " );
6 scanf ( " % s " , phrase );
7 printf ( " Phrase is % s \ n " , phrase );
8 printf ( " Enter a second phrase : " );
9 scanf ( " % s " , phrase2 );
10 printf ( " Phrase is % s \ n " , phrase2 );
11 return 0;
12 }
• Write the rest of the output exactly how is should be after the user in-
puts the following text from the parital sample output above. In other
words, what will be displayed to the terminal after the first scanf state-
ment when collecting She-Hulk Attorney at Law from the keyboard?
Phrase is She-Hulk
Enter a second phrase: Phrase is Attorney
• What is exactly left in the standard input stream after line 6 executes?
Attorney at Law
• What is exactly left in the standard input stream after line 9 executes?
at Law
2
COP 3223
Question 2
arr 'I' 'n' 't' 'r' 'o' 'T' 'o' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0'
arr2 'T' 'o' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0'
arr3 'C' ' ' 'P' 'r' 'o' 'g' 'r' 'a' 'm' 'm' 'i' 'n' 'g' '\0' '\0'
arr 'I' 'n' 't' 'r' 'o' 'T' 'o' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0'
arr2 'T' 'o' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0'
arr3 't' 'r' 'o' 'T' 'o' '\0' 'r' 'a' 'm' 'm' 'i' 'n' 'g' '\0' '\0'
arr 'I' 'n' 't' 'r' 'o' 'T' 'o' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0'
arr2 'T' 'o' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0' '\0'
arr3 't' 'r' 'o' 'T' 'r' 'o' 'r' 'a' 'm' 'm' 'i' 'n' 'g' '\0' '\0'
3
COP 3223
Question 3
4
COP 3223
Question 4
Write a user defined function definition called noSpace. The function has one
parameter, a string called s1. The function replaces every space character
(’ ’) in the string parameter with an underscore (’ ’). The function does
not return anything. Assume the character library was already imported.
void noSpace ( char s1 [])
{
for ( int x = 0; x < strlen ( s1 ); ++ x )
if ( s1 [ x ] == ’ ’)
s1 [ x ] = ’_ ’;
}
5
COP 3223
Question 5
6
COP 3223
Question 6
typedef struct {
int code ;
char subject [4];
char * instructor ;
int credits ;
} course_t ;
7
COP 3223
Question 7
Draw a visualization of the memory state (both stack and heap space) of
what is happening after lines 4 and 5 are executed.
8
COP 3223
Question 8
free(myarray[0].word);
free(myarray);
9
COP 3223
Question 9
Write a user defined function definition called palindrome that has one
string parameter called stuff and a second parameter that holds an integer
value called size which represents the number of characters in the string.
The function will determine if the string in stuff is considered a palindrome
or not. If the string is a palindrome, the function returns 1. Otherwise return
0. A string is said to be palindrome if it reads the same backward as forward.
Examples of palindrome strings, level, refer, aabaa, and abccba are a few of
many examples of what is considered a palindrome.
int palindrome ( char stuff [] , int size )
{
for ( int x = 0; x < size / 2; ++ x )
if ( stuff [ x ] != stuff [ size - x - 1])
return 0;
return 1;
}
10
COP 3223
Question 10
} employee_t ;
11
COP 3223
Question 11 Given the following code. Assume r and c are variables al-
ready declared and initialize to proper values.
int ** a = ( int **) malloc ( r * sizeof ( int *));
for ( int i = 0; i < r ; i ++)
a [ i ] = ( int *) malloc ( c * sizeof ( int ));
Are the variables a and b exactly the same in terms of implementation and
how it is stored in memory of a 2D dynamic array? If not, explain the dif-
ference. You are welcome to draw a visualization to help your explanation.
12
COP 3223
Question 12 Given the following code. Assume r and c are variables al-
ready declared and initialize to proper values.
char ** words = ( char **) malloc ( r * sizeof ( char *));
if ( flag == 0)
printf ( " No Duplicate !\ n " );
13