Review Questions
You’ll find answers to the review questions in Appendix A, “Answers to the Review Questions.”
Which data type would you use for each of the following kinds of data (sometimes more than one type could be appropriate)?
- The population of East Simpleton
- The cost of a movie on DVD
- The most common letter in this chapter
- The number of times that the letter occurs in this chapter
- Why would you use a type long variable instead of type int?
- What portable types might you use to get a 32-bit signed integer, and what would the rationale be for each choice?
Identify the type and meaning, if any, of each of the following constants:
- '\b'
- 1066
- 99.44
- 0XAA
- 2.0e30
Dottie Cawm has concocted an error-laden program. Help her find the mistakes.
include <stdio.h> main ( float g; h; float tax, rate; g = e21; tax = rate*g; )
Identify the data type (as used in declaration statements) and the printf() format specifier for each of the following constants:
- 12
- 0X3
- 'C'
- 2.34E07
- '\040'
- 7.0
- 6L
- 6.0f
- 0x5.b6p12
Identify the data type (as used in declaration statements) and the printf() format specifier for each of the following constants (assume a 16-bit int):
- 012
- 2.9e05L
- 's'
- 100000
- '\n'
- 20.0f
- 0x44
- -40
Suppose a program begins with these declarations:
int imate = 2; long shot = 53456; char grade = 'A'; float log = 2.71828;
Fill in the proper type specifiers in the following printf() statements:
printf("The odds against the %__ were %__ to 1.\n", imate, shot); printf("A score of %__ is not an %__ grade.\n", log, grade);
- Suppose that ch is a type char variable. Show how to assign the carriage-return character to ch by using an escape sequence, a decimal value, an octal character constant, and a hex character constant. (Assume ASCII code values.)
Correct this silly program. (The / in C means division.)
void main(int) / this program is perfect / { cows, legs integer; printf("How many cow legs did you count?\n); scanf("%c", legs); cows = legs / 4; printf("That implies there are %f cows.\n", cows) }
Identify what each of the following escape sequences represents:
- \n
- \\
- \"
- \t