Data Structures Quiz


Identification:

Last Name:     

First Name:    

Class Section: 

Matching

Type the letter of the term which best matches the following descriptions (you may use the same answer more than once or not at all) :

Terms
a) & b) string c) index
d) dot operator e) * f) pointer
g) array h) struct i) \0

Descriptions
1. collection of ordered values 2. array of characters, ending with null character 3. address operator
4. variable assigned an address 5. user defined data type 6. indirection operator
7. components are of same data type 8. used in declaration of pointer 9. components can be of different data types
10. used to specify one element of array 11. null character 12. used to specify one member of struct

Put the letter of the best answer for the following:

13. What is the expected output for the following segment of code?

int vals [4] = {3, 6, 9, 12};
printf ("%i", vals[1]);

a. 3
b. 6
c. 9
d. 12
e. none of the above
Answer:  

14. The following for loop was started to print out the
elements in the vals array (declared in #13). What
should the loop condition be?

int i;
for (i=0; loop condition; ++i)
    body of loop

a.  i < 4;
b.  i <= 4;
c.  i < 5;
d.  i <= 5;
e.  none of the above 
Answer:  

15. What should the body of loop be, from the code in #14?

a. printf ("%i ", vals[1-4]);
b. printf ("%i ", vals[0-3]);
c. printf ("%i ", vals[1]);
d. printf ("%i ", vals[i]);
e. none of the above
Answer:  

16. What does the following code do:

struct cat
{
   char color [10];
   int age;
   char gender;
};

a. declare a variable called struct cat.
b. define a data type called struct cat.
c. declare 3 variables: color, age, and gender.
d. declare 4 variables: cat, color, age, and gender.
e. none of the above
Answer:  

17. Assume that values were assigned to the variable Tiger, declared below.  
What code will print out the age of Tiger:

struct cat Tiger;

a. printf("Tiger's age is %i ",age);
b. printf("Tiger's age is %i ",Tiger);
c. printf("Tiger's age is %i ",Tiger[age]);
d. printf("Tiger's age is %i ",Tiger.age);
e. none of the above
Answer:  

18. What is the output from the following code:

int NUM = 10;
int *x;
x = &NUM;
printf ("%i ", *x);

a. x
b. 10
c. &NUM
d. *x
e. none of the above
Answer:  

19. What is the result of the following code:

char LETTER;
char *P, *W;
P = &LETTER;
*P = 'J';
W = P;
printf ("%c ", LETTER);

a. P
b. W
c. J
d. *
e. none of the above
Answer:  

20. Using the same code given in #19, what would be the ouput
from the following printf statement?

printf ("%c ",*W);

a. P
b. W
c. J
d. *
e. none of the above
Answer:  

21. What code will assign whatever the user types to the variable name:

char name [10];

a. scanf ("%c", &name);
b. scanf ("%s", &name);
c. scanf ("%c", name);
d. scanf ("%s", name);
e. none of the above
Answer:  

22. What code will print out what was assigned to the variable name:

a. printf ("%c", name[]);
b. printf ("%s", name[]);
c. printf ("%c", name);
d. printf ("%s", name);
e. none of the above
Answer: