CS 215: UNIX C Programming

Review for Quiz 4
 
  1. A function is a self-contained unit of program code design to _____.
    1. replace main()
    2. trap all input errors
    3. accomplish a particular task
    4. avoid I/O files


  2. Functions do all of the following EXCEPT
    1. Make a program easier to read.
    2. Make a program more modular.
    3. Make a program easier to repair.
    4. Make a program bug free.


  3. Which of the following best explains the statement
    void starbar(void)
    1. function prototype
    2. function definition
    3. function call
    4. function declaration


  4. What is another way of writing the following statements?
    if (n < m)
    return (n);
    else
    return (m);
    1. return (n < m) ? n : m;
    2. (n < m) return ? n : m;
    3. return (n < m) ? return (n) : return (m);
    4. return (n < m) ? return (n : m);


  5. A function with no return value should be declared as type ___.
    1. void
    2. int
    3. null
    4. float


  6. A function ___ informs the compiler which type the function is, but the function ___ supplies the actual code.
    1. definition, call
    2. declaration, definition
    3. definition, declaration
    4. call, declaration


  7. When a function calls itself, it is termed ___.
    1. recession
    2. recessing
    3. receiving
    4. recursion


  8. What is the maximum number of times a function can call itself?
    1. zero
    2. once
    3. twice
    4. There is no upper limit.


  9. With a recursive call, each call is balanced with a ___.
    1. prototype
    2. return
    3. argument
    4. EOF


  10. Although each level of recursion has its own ____, the ___ itself is not duplicated.
    1. parameters, recursive call
    2. argument list, function
    3. set of variables, code
    4. prototype, function call


  11. Binary notation represents numbers in terms of powers of ___
    1. 0 or 1
    2. 2
    3. 10
    4. Both a and b are correct.


  12. In which directory would the following include file be found? #include "hotels.h"
    1. system library directory
    2. current working directory
    3. system .h directory
    4. main .h directory


  13. A pointer is a variable used to store a(n) ____.
    1. operand
    2. operator
    3. variable
    4. address


  14. Which of the following statements will display the address of the variable pooh, where pooh = 24;
    1. printf(" %d", &pooh);
    2. printf(" %d", *pooh);
    3. printf(" %p", &pooh);
    4. printf(" %p", *pooh);


  15. In C, each function uses ___ variables.
    1. it's own
    2. shared
    3. duplicate sets of
    4. common


  16. Which of the following completes the swap of the variables x and y, given the statements
    temp = x;
    x = y;
    1. y = x;
    2. y = temp;
    3. x = temp;
    4. temp = y;


  17. ___ is a pointer variable and ___ may be a regular variable, given the statement
    ptr = &pooh;
    1. ptr, pooh
    2. pooh, ptr
    3. Both a and b are correct.
    4. None of the above are correct.


  18. Which of the following statements finds the value (val) that ptr, a pointer variable, points to?
    1. val = & ptr;
    2. val = * ptr;
    3. ptr = & val;
    4. ptr = * val;


  19. Which of the following declares pi as a pointer to int?
    1. int pi;
    2. int * (&pi);
    3. int & pi;
    4. int * pi;


  20. Which of the following passes the address of x and y to the function change_them()?
    1. change_them( &x, &y);
    2. change_them( x, y);
    3. change_them( *x, *y);
    4. change_them( &(*x), &(*y));


  21. Given the following function call, which of the following function headings is correct? change_it (&x, &y);
    1. void change_it (int x, int y)
    2. void change_it (int &x, int &y)
    3. void change_it (int *x, int *y)
    4. void change_it (*int x, *int y)


  22. What are the values 5 and 2, given that they are assigned to a and b, respectively, in the statement
    c = diff(a, b);
    1. formal arguments
    2. informal arguments
    3. actual arguments
    4. pointer arguments


  23. Functions must have the same ___ as the value they return.
    1. value
    2. type
    3. address
    4. argument


  24. An array is composed of a series of ___ of one data type.
    1. elements
    2. articles
    3. subscripts
    4. events


  25. All of the following are C storage classes except which one?
    1. external
    2. public
    3. static
    4. automatic


  26. Which one of the following storage classes is used to define a variable or array outside a function?
    1. external
    2. public
    3. private
    4. automatic


  27. Which one of the following would be used to initialize an array?
    1. int shows[5] = [12, 10, 8, 9, 6];
    2. int shows[5] = [12, 10, 8, 9, 6, ];
    3. int shows[5] = {12, 10, 8, 9, 6 };
    4. int shows[5] = {12, 10, 8, 9, 6, };


  28. Which one of the following storage classes is placed inside a function, but retains its value(s) between function calls?
    1. external
    2. public
    3. static
    4. automatic


  29. Which keyword serves to remind the programmer that an array is defined elsewhere in the program as an external?
    1. ext
    2. extern
    3. external
    4. ex


  30. If you do not initialize an automatic array, all array elements are set to _________.
    1. NULL
    2. 0
    3. 1
    4. Garbage values


  31. When empty ____ are used to initialize an array, the compiler will count the number of items in the list and make the array that large.
    1. brackets []
    2. braces {}
    3. parentheses ()
    4. pipes ||


  32. Adding 1 to a pointer increases its value by the size, in ___ of the pointed to object.
    1. words
    2. bits
    3. bytes
    4. units


  33. Which of the following shows two ways of specifying the same address (where dates is an array of type int)?
    1. *dates + 2 == dates[2]
    2. dates + 2 == *dates[2]
    3. *(dates + 2) == dates[2]
    4. dates + 2 == &dates[2]


  34. Which one of the following shows two ways to specify the same value (where dates is an array of type int)?
    1. *dates + 2 == dates[2]
    2. dates + 2 == *dates[2]
    3. *(dates + 2) == dates[2]
    4. dates + 2 == &dates[2]


  35. Which one of the following adds 2 to the first element of dates (where dates is an array of type int)?
    1. *dates + 2
    2. dates + 2
    3. *(dates + 2)
    4. dates + 2


  36. When an array name is used in a function call, you actually pass the ___ of the ___ element(s) to the called function.
    1. value, first
    2. value, all
    3. address, first
    4. address, last


  37. Which one of the following will add 1 to an array element (where ptr is a pointer to int)?
    1. *ptr++
    2. *++ptr
    3. (*ptr)++
    4. *(ptr++)


  38. Which of the following statements is valid, given the code int urn[3]; int * ptr1;
    1. urn++;
    2. ptr = urn++;
    3. ptr++;
    4. Both b and c are valid.


  39. How many elements does the following array contain?
    rain[3][10][3]
    1. 36
    2. 40
    3. 60
    4. 90


  40. Two-dimensional arrays are also called _____ of arrays.
    1. many-to-many
    2. multiple-element
    3. an array
    4. functional


  41. The declaration format for a one-dimensional array is?
    1. type name {size};
    2. type name [size];
    3. type &name[size];
    4. type *name[size];