CS 216

Review for First Quiz

  1. A character string is a ___ array terminated by ___.
    1. char, \n
    2. int, \0
    3. char, \0
    4. int, \n


  2. Which one of the following initializes a string array?
    1. char name[] = "ABC";
    2. char name[] = {'A', 'B', 'C'};
    3. char name[] = {ABC};
    4. char name[] = {'A', 'B', 'C', \0 };


  3. What is the chief difference between these two statements? static char heart[] = "I love Vanillie!"; char *head = "I love Millie!";
    1. head is a constant
    2. heart is a variable
    3. head is a variable
    4. heart is undefined


  4. Explain what happens, given the following code: static char *mesg = "Don't be a fool!"; static char *copy; copy = mesg;
    1. The string defined in mesg will be assigned to copy.
    2. The address mesg points to will be assigned to copy.
    3. The value of mesg will be assigned to copy.
    4. A compiler error will occur.


  5. The following function header indicates that gets() returns a ___. char * gets(char * s)
    1. string constant
    2. character constant
    3. pointer to char
    4. pointer to a pointer


  6. What is NULL in the following statement? while(gets(name) != NULL) continue;
    1. The NULL character
    2. Zero
    3. 1
    4. An address


  7. The scanf() function is more of a ___ function.
    1. get string
    2. get word
    3. get until NULL pointer
    4. get until newline


  8. Compared to scanf(), gets() has all of the following advantages except which one?
    1. easier to use
    2. faster
    3. best for one word
    4. more compact


  9. What argument type is required by the puts() function?
    1. a variable name
    2. a string address
    3. a string constant
    4. Both a and c are correct.


  10. Which of the following means the same as the statement: printf(" %s\n", string);
    1. puts(*string);
    2. puts("string");
    3. puts(\nstring);
    4. puts(string);


  11. Which string function adds a copy of the second string to the end of the first, to form a new, combined string?
    1. strlen()
    2. strcat()
    3. strcpy()
    4. strcmp()


  12. Which header file contains function prototypes for the C family of string functions?
    1. string.h
    2. io.h
    3. stdio.h
    4. mytype.h


  13. With the string compare function, what value is returned if the two strings are the same?
    1. -1
    2. 0
    3. 1
    4. EOF


  14. The sprintf() function is useful for executing which one of the following?
    1. Comparing two strings
    2. Determining print speed
    3. Executing system commands
    4. Concatenating two strings


  15. All of the following are character-testing functions, except which one?
    1. isprint()
    2. isword()
    3. islower()
    4. isspace()


  16. A ___ line is the line you type to run your a program.
    1. argument
    2. system
    3. command
    4. comment


  17. What does argc stand for in the heading
    int main(int argc, char * argv[])
    1. any character
    2. argument character
    3. a range count
    4. argument count


  18. Which one of the following means the same as
    int main(int argc, char *argv[])
    1. int main(int *argc, char *argv[])
    2. int *main(int argc, char argv[])
    3. int main(int argc, char ** argv)
    4. int main(int argc, *(char *argv))


  19. Command-line arguments are read as ____.
    1. character constants
    2. strings
    3. numeric variables
    4. Both as strings and as numbers


  20. All of the following are string to number conversion functions, except which one?
    1. atof()
    2. atoi()
    3. atol()
    4. atop()


  21. A ___ is a named section of storage, usually on a disk.
    1. pointer
    2. file
    3. array
    4. string


  22. The two ANSI-mandated views of a file are ___ and ___.
    1. text, inline
    2. binary, random
    3. random, inline
    4. binary, text


  23. Which three files does C open automatically?
    1. sdin, sdout, sderr
    2. sdi, sdo, sde
    3. stdin, stdout, stderr
    4. stin, stout, sterr


  24. Which function causes a program to terminate, closing any open files?
    1. stop()
    2. exit()
    3. quit()
    4. end()


  25. All of the following are file mode strings for fopen(), except which one?
    1. "u"
    2. "r"
    3. "w"
    4. "a"


  26. Which of the following mode strings opens a file for update (for reading and writing)?
    1. "r+"
    2. "u+"
    3. "a"
    4. "w"


  27. What type of statement is the following? FILE *fp;
    1. declares a pointer to an int
    2. declares a pointer to a character array
    3. declares a pointer to FILE
    4. declares a pointer to NULL


  28. When fp is a pointer to FILE, which one of the following means the same as ch = getchar();
    1. ch = gets(fp);
    2. ch = gets;
    3. ch = getc;
    4. ch = getc(fp);


  29. Which one of the following means the same as putc(ch, stdout);
    1. puts(ch);
    2. putc(ch);
    3. putchar(stdout);
    4. putchar(ch);


  30. If fp is a pointer of type FILE, which one of the following functions is used to close a file?
    1. fclose();
    2. fclose(fp);
    3. close(FILE *fp);
    4. close(fp);


  31. Which one of the following is the general format of the fgets() function?
    1. fgets(buf, MAX, fp);
    2. fgets(fp, MAX, buf);
    3. fgets(fp, buf, MAX);
    4. fgets(buf, fp, MAX);


  32. Which one of the following is the general form of the fputs() function?
    1. fputs(buf, MAX, fp);
    2. fputs(fp, MAX, buf);
    3. fputs(buf, fp);
    4. fputs(fp, buf);


  33. The ___ function enables you to treat a file like an array and move directly to any particular byte in a file opened by fopen().
    1. flook()
    2. fget()
    3. fseek()
    4. fpick()


  34. Under ANSI, all of the following modes can be used with fseek(), except which one?
    1. SEEK_BEG
    2. SEEK_CUR
    3. SEEK_END
    4. SEEK_SET


  35. In random access processing, which of the following functions returns the current file location?
    1. fcur()
    2. fend()
    3. fseek()
    4. ftell()


  36. Calling the following function begins a process called ____?
    int fflush(FILE *fp)
    /* this is the function header, not a call */
    1. filling a buffer
    2. floating a buffer
    3. fast-forwarding a buffer
    4. flushing a buffer


  37. Which one of the following functions returns a nonzero error if a read or write error has occurred during file processing?
    1. feof()
    2. ferror()
    3. ferr()
    4. feoff()


  38. A pointer-to-void type is written as _______.
    1. void ptr
    2. (void *) ptr
    3. (*void) ptr
    4. void * ptr


  39. Random access file processing works better in ___ than in ___ mode.
    1. fscanf(), fprintf()
    2. binary, text
    3. text, binary
    4. text, character