Digital Music Programming
Final Exam (Fujinaga, December 1997)
(5 points per question)
1. If
short tic[4][3] = {{6}, {5, 4}, {3, 2}};
what is?
a. tic[2][0] - tic[1][0] * 2
b. *(&tic[0][0] + 6)
c. **tic + 2 d. **(tic + 2) + 1
e. *(*(tic + 2) + 1) + 2
2. What are the results of the following expressions?
a. 2 && 3 || 3 && 2
b. 2 < 3 & 3 > 2
c. 2 + 3 == 3 << 2
d. (2 > 3) ? 3 + 2 && 2 - 3: (3 * 2) >> 2
e. 2 < 3 << 3 + 2
3. What does the function below do? Assume q and p are strings.
char *func(char *q, char *p, int n)
{
>char *t = q;
while (*q++)
;
q--;
n++;
while (--n)
if (!(*q++ = *p++))
{
q--;
break;
}
*q = 0; return(t);
}
4. Explain each of the following:
a. long (*x)[5];
b. int *(*mat[3])[2];
c. struct people *(*c[4])();
d. float (**pic())[3];
e. char (*(*(*xyz[2])[3])())[4];
5. Write a function that rotate bits of a variable of type unsigned
short and returns the result.
unsigned short rotate(unsigned short number, short shift);
The positive shift amount should shift the bits of the number to the left
and a negative shift amount should shift it to the right. Rotate implies
that if the bits are shifted to the left the bits wraps around to the right,
e.g.:
10111000 rotate by 3 will be 11000101
10111000 rotate by -4 will be 10001011
Hints: Use masks and treat the left and right rotates separately.
6. Create an appropriate declaration for each of the following variables:
a. min is an array of 24 pointers to struct tabs
b. stop is a pointer to an array of 10 longs
c. name is an array of 8 pointers to struct people
d. form is an array of 5 by 3 pointers to functions returning double
e. hard is a pointer to a function returning array of 3 pointers to char