Quiz — Functions and argument pointers
This quiz covers the definition and use of functions. Details that are tested here include the use of pointers to allow functions (including scanf) to change values in code that calls them and the use of the strcpy and strcmp functions accessible through <string.h>.
Readings
House, chapter 7, sections 5.1, 5.2, 5.3, 12.1 and 12.2, and material on <string.h> in chapters 3 and 6.
Kernighan and Ritchie, chapters 1 through 4 except sections 1.10, 3.8, 4.3, 4.5, 4.6, 4.7, 4.10, 4.11.2, and 4.11.3. You will not be tested on material on arrays in chapters 2 through 4.
Suggested exercises
House, "short answer" self-test exercises and test questions in chapters 5 and 7. You may also be asked to write small program segments.
Sample quiz
c = 'a'; putchar (c); putchar (F(c)); putchar (c);Assume that the function F has been defined as follows:char F (char c) { c = 'f'; return (c); }
- Modify the code from exercise 1 so that, on return from the F function, the variable c in the calling code contains the character 'f'.
- Write a function AllDone that, given a string as argument, returns a true value if the string is "exit" and returns false otherwise.
- Write a function GetWordAndValue that prompts the user for a string and an integer, reads the values, and returns both to the calling program. Assume that the caller has already provided space in memory for all the characters of the word.
- Write a main program that calls GetWordAndValue and echoes the values returned.