CSC 105 Section:
Name:
Student ID:
Final exam CSC105 - Winter 1997
int quack = 8 ;
quack += 5 ;
quack -= 6 ;
quack *= 10 ;
quack /=2 ;
quack %= 3 ;
2. What is the output of the following fragment for the indicated input (assume that ch is type int and that the input is buffered)?
The input is as follows:
Duralex [enter]
The fragment is as follows:
while( ( ch =getchar() ) != ‘\n’ )
{
putchar(ch++) ;
putchar(ch++) ;
putchar(--ch) ;
}
3. Consider a book database in which you have to store the following information about each book:
title - a string of maximum 30 characters
publisher - a string of maximum 30 characters
author - a string of maximum 30 characters
ISBN - a long integer
price - a floating point number
4. Consider the declarations:
char string[] = { "This is a string" } ;
char * p1, * p2 ;
char c;
Which of the following instructions are correct? If the instructions are correct, describe their effect in sequence (i.e. when an instruction is executed you assume all (correct) previous instructions have already been executed).
p1 = string ;
p2 = &string[0] ;
c = *p1++ ;
p2 = p1 + 2 ;
*p2 = ‘t’ ;
putchar(c) ;
*(p2-1) = ‘a’ ;
p2 = &p1 ;
printf("%s\n", string) ;
5. Consider the following declarations:
struct cell
{
int key ;
struct cell *next, *prev ;
} ;
struct cell c1, c2, *p1, *p2 ;
Draw two pictures which will reflect the situation in memory before and after the execution of the following instructions (if they are correct). If you find an error of any type, explain it.
p1 = &c1 ;
p2 = &c2 ;
p2->key = 10 ;
p2->next = p1 ;
(p2->next)->key = 20 ;
p2->prev = NULL ; /* NULL is just 0 */
(p2->next)->prev = p1 ;
p1->next = NULL ;
6) Write a C program which will:
Example: If the content of the first array was 1,2,3,4,2, the content of the second array should be 1-2=-1, 2-3=-1, 3-4=-1, 4-2=2. The program should print 1,2,3,4,2 and –1,-1,-1,2. Note that the second array has one element less than the first one.