Digital Music Programming

Mid-term Exam (Fujinaga, October 1997)

1. Find the error in the following, specify syntactical or semantic errors (10 pnts):

#include <stdio.h>

define MAX 10

int main(null)

{

int i; j; vec[MAX];

for (i = 1; i <= max, i--);

{

list[i] = i;

for (j= 1, j >=i, j++)

print("%d/n". vec[j]);

retrun(0.)

}

2. What does the following print (8 pnts)?

#include <stdio.h>

main()

{

int num = 7;

printf("%d\n", -num);

printf("%d\n", ++num);

printf("%d\n", num++);

printf("%d\n", num--);

printf("%d\n", num -= num);

printf("%d\n", --num);

printf("%d\n", num * num);

printf("%d\n", --num + num++);

}

Digital Music Programming

Mid-term Exam (Fujinaga, October 1997) (cont.)

3. (12 pnts)

a) Convert binary 10110 to decimal

b) Convert binary 111101 to hexadecimal

c) Convert hexadecimal 0xE3 to decimal

d) Convert hexadecimal 0x4A to binary

e) Convert decimal 86 to hexadecimal

f) Convert decimal 23 to binary

4. What does the following print (10 pnts)?

#include <stdio.h>

int main(void)

{

int i = 0;

while (++i < 5)

printf("%d ", i % 2);

do

printf("%d ", i / 3);

while ((i-- > 0) ? 2 : 0);

return(0);

}

5. Evaluate the following expressions (6 pnts):

a) 44 / 7

b) 7 / 44

c) 44 % 7

d) 7 && 44

e) 44 || 7

f) 7 > 44