CS 215: UNIX C Programming

Review for Quiz 1
 

Go over the following questions to prepare for your quiz.

  1. In C, the _______ data type can hold numbers with decimal points and the ____ data type can hold a single character.
    1. int, char
    2. char, int
    3. int, float
    4. float, char


  2. Which function is used to provide keyboard input to a computer?
    1. scanf()
    2. printf()
    3. enter()
    4. keyf()


  3. When the computer asks you for information and then uses the number you type in, the program is said to be _______________.
    1. interceptive
    2. closed
    3. interactive
    4. batched


  4. Data which are preset before a program is used and which keep their values unchanged throughout the life of the program are called ___________.
    1. variables
    2. float point
    3. regular
    4. constants


  5. Data which may change or be assigned values as a program runs are called __________.
    1. variables
    2. float point
    3. regular
    4. constants


  6. All of the following are variations of forms of type int except which one?
    1. long
    2. double
    3. unsigned
    4. short


  7. The smallest unit of memory is called a _____.
    1. bite
    2. bin
    3. bit
    4. byte


  8. Which one of the following is a number with NO fractional part?
    1. integer
    2. floating-point number
    3. real number
    4. Both a and c are correct answers.


  9. Which one of the following data types can store the largest range of values?
    1. long double
    2. float
    3. double
    4. long float


  10. The int data type is a(n) ___________ integer.
    1. unsigned
    2. signed
    3. real
    4. unreal


  11. Which one of the following is an invalid declaration of a variable of type int?
    1. int erns;
    2. int hogs, cows;
    3. int horses, int cows;
    4. None of the above are invalid declarations.


  12. All of the following are valid integer constants except which one?
    1. 0
    2. -44
    3. 12.3
    4. 22


  13. Which one of the following conversion specifiers is used to print a hexadecimal?
    1. %d
    2. %o
    3. %x
    4. %h


  14. The numeric range of a variable of type int is ______________.
    1. -12767 to +12767
    2. -22767 to +22767
    3. -32767 to +32767
    4. -42767 to +42767


  15. All of the following are valid ANSI C types, except which one?
    1. unsigned short
    2. long unsigned int
    3. short int
    4. unsigned


  16. All of the following are true about integer types, except which one?
    1. Use short to save storage space.
    2. Use long to speed up calculations.
    3. Use unsigned for counting.
    4. Use short if numbers are small.


  17. To print a variable of type long int, which conversion specifier is required?
    1. %ld
    2. %li
    3. %l
    4. %lf


  18. To print a variable of type short int, which conversion specifier is required?
    1. %sd
    2. %d
    3. %hd
    4. Both b and c are correct answers.


  19. Variables of type char are actually _______ and not __________.
    1. characters, letters
    2. integers, numbers
    3. characters, integers
    4. integers, characters


  20. The standard ASCII code runs numerically from 0 to what?
    1. 64
    2. 127
    3. 256
    4. 512


  21. Which one of the following would be used to print the sentence: Gramps sez, " a \ is a backslash."
    1. printf("Gramps sez, \"a \ is a backslash."\n");
    2. printf("Gramps sez, \"a \ is a backslash.\"\n");
    3. printf("Gramps sez, \"a \ \\is a backslash.\"\n");
    4. printf("Gramps sez, \"a \\ is a backslash.\"\n");


  22. A string of characters enclosed in double quotes in a printf() is called a character _____.
    1. string
    2. rope
    3. wire
    4. twine


  23. Which one of the following is a correct scanf() statement, given the code: char ch; printf("Please enter a character.\n");
    1. scanf("%c", ch);
    2. scanf("%c", #ch);
    3. scanf("%c", $ch);
    4. scanf("%c", &ch);


  24. The exponential notation for the number 1,000,000 is _________.
    1. 1.0 X9
    2. 1.0o9
    3. 1.0e9
    4. 1.0L9


  25. By default, the C compiler assumes that floating point constants are __________ precision.
    1. single
    2. double
    3. long single
    4. long double


  26. Which conversion specifier is required for a variable of type double?
    1. %d
    2. %s
    3. %c
    4. %f


  27. C has a built-in operator called ____________ that returns the size of a variable in bytes.
    1. bytesize
    2. size
    3. sizeof
    4. size_of


  28. Which of the following initializations is correct?
    1. int apples = 56000;
    2. float apples = 53e45;
    3. char letter = "A";
    4. double range = 65.3;


  29. How many additional arguments can the following partial printf() expect? printf("%d cats ate %d cans of tuna\n", );
    1. zero
    2. 1
    3. 2
    4. 3


  30. Under ANSI C, flushing the buffer occurs when
    1. the buffer gets full.
    2. a newline character is encountered.
    3. there is impending input.
    4. All of the above are correct answers.


  31. Which conversion character is used to handle the input and output of a character string?
    1. %c
    2. %s
    3. %f
    4. %d


  32. Which of the following functions finds the length of a string?
    1. stlen()
    2. string()
    3. slength()
    4. strlen()


  33. Which character is placed at the end of a character string?
    1. \t
    2. \0
    3. \e
    4. \s


  34. (A)n ____ is an ordered sequence of data elements of one type.
    1. store
    2. subscript
    3. integer
    4. array


  35. In general, one call to scanf() can used with one %s to read how many words?
    1. 1
    2. 2
    3. 3
    4. More than 3.


  36. When storing the string constant, "X", how many characters are actually stored?
    1. 0
    2. 1
    3. 2
    4. 3


  37. Which .h header file contains the prototype for the string length function?
    1. stdio.h
    2. str.h
    3. strlen.h
    4. string.h


  38. When using printf(), you cannot break a string (move part of it to a second line) between _________.
    1. the quotation marks
    2. arguments
    3. commas
    4. Both a and b are correct answers.


  39. How many memory cells are required to store the following array: char name[40];
    1. 2
    2. 20
    3. 40
    4. 41


  40. Which of the following sizeof statements is(are) correct, given the code: char name[40];
    1. sizeof(name)
    2. sizeof name
    3. sizeof name[40]
    4. Both a and b are correct answers.


  41. What type of constant is pi, given the statement: circumference = pi * diameter;
    1. regular
    2. manifest
    3. symbolic
    4. solid


  42. Which of the following is a valid preprocessor directive?
    1. #define .015 TAXRATE
    2. #define SIZE 12
    3. #define MILES = 10
    4. #define FEET 5280;


  43. Defined constants using #define are termed ______ constants.
    1. regular
    2. manifest
    3. symbolic
    4. solid


  44. The conversion specifier %1.3f rounds a floating point number to how many places?
    1. 1
    2. 2
    3. 3
    4. 4


  45. Where does the compiler look first, given the statement: #include "const.h"
    1. The nearest system directory.
    2. stdio.h
    3. string.h
    4. The current directory.


  46. All of the following are valid printf() conversion specifiers, except which one?
    1. %c
    2. %x
    3. %o
    4. %a


  47. Which conversion specifier would you use if you wish to print 12%, where 12 is stored in a variable of type int?
    1. %%d
    2. %d%
    3. d%%
    4. %d%%


  48. Which printf() flag is used to left-justify the display of a field value?
    1. -
    2. #
    3. +
    4. L


  49. The conversion specifier %5.2f prints a float which is ___ characters wide, with ___ digits after the decimal point.
    1. 7, 2
    2. 5, 2
    3. 3, 2
    4. 5, 3


  50. What will be displayed, given the following statements? #define BLURB "Outstanding!" int main(void) { printf("%15.5s\n", BLURB); }
    1. Outst
    2. BLURB
    3. "Outs
    4. Outstanding


  51. In ANSI C, what value is returned by the printf() function?
    1. The letters inside the double quotes.
    2. The length in bytes of the displayed message.
    3. The number of characters it printed.
    4. No value is returned by printf().


  52. The scanf() function converts ____ input into various forms.
    1. integers
    2. floating-point numbers
    3. strings
    4. All of the above are correct.


  53. If you use scanf() to read a string into a character array
    1. precede the variable name with an &.
    2. precede the variable name with a #.
    3. precede the variable name with a %.
    4. don't use &, #, or %.


  54. If you use a field width with scanf(), the function halts
    1. at the field end.
    2. at the first whitespace.
    3. Both a and b are correct.
    4. A field width cannot be used with scanf().


  55. In ANSI C, what value is returned by the scanf() function?
    1. The number of characters read.
    2. The length in bytes of the letters entered.
    3. The letters entered at the keyboard.
    4. No value is returned by scanf().


  56. The abbreviation EOF stands for
    1. error on float
    2. end of file
    3. error on file
    4. end of float


  57. The * modifier used with scanf() causes the function to ___ corresponding input.
    1. add
    2. concatenate
    3. skip over
    4. merge


  58. All of the following are scanf() conversion specifiers, except which one?
    1. %c
    2. %f
    3. %r
    4. %s


  59. With printf(), which one of the following pads the field width with leading zeros instead of spaces?
    1. %010d
    2. %#10d
    3. %%10d
    4. %*10d


  60. With printf(), which one of the following informs the C program to specify the field width of a variable?
    1. %0d
    2. %#d
    3. %%d
    4. %*d