1. Which data type would you use for each of the following kinds of data(sometimes more than one type could be appropriate)?
a. The population of East Simpleson
b. The cost of a movie on DVD
c. The most common letter in this chapter
d. The number of times that the letter occurs in this chapter
a. int b. float c. char d. int
2. Why would you use a type long variable instead of type int ?
one reason is that long may accommodate larger numbers than int on your system; another reason is that if you do need to handle larger values, you improve portability by using a type guaranteed to be at least 32 bits on all systems.
3. What portable types might you use to get a 32-bit signed integer, and what would the rationale be for each choice?
To get exactly 32 bits, you could user int32_t, provided it was defined for your system. To get the smallest type that could store at least 32 bits, use int_least32. And to get the type that would provide the fastest computations for 32 bits, choose int_fast32_t.
4. Identify the type and meaning, if any, of each of the following constants:
a. ''
b. 1066
c. 99.44
d. 0XAA
e. 2.0e30
a. char constant(but stored as type int)
b. int constant
c. double constant
d. unsigned int constant, hexadecimal format
e. double constant
6. Identify the data type (as used in declaration statements) and the printf() format specifier for each of the following constants:
Constant |
Type |
Specifier |
a. 12 |
int |
%d |
b. 0X3 |
unsigned int |
%#x |
c. ‘C’ |
char(really int) |
%c |
d. 2.34E07 |
double |
%f |
e. '040' |
char(really int) |
%c |
f. 7.0 |
double |
%f |
g. 6L |
long |
%ld |
h 6.0f |
float |
%f |
i 0x5.b6p12 |
float |
%a |
7. 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 ):
Constant |
Type |
Specifier |
a. 012 |
unsigned int |
%#o |
b. 2.9e05L |
long double |
%Le |
c. 's' |
char(really int) |
%c |
d. 100000 |
long |
%ld |
e. ' ' |
char(really int) |
%c |
f. 20.0f |
float |
%f |
g. 0x44 |
unsigned int |
%x |
h. -40 |
int |
%d |
8. 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.
", imate, shot);
printf("A score of %__ is not an %__ grade.
", log, grade);
%d %ld
%f %c
9. 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.)
ch = '
';
ch = 13;
ch = ' 15';
ch = 'xd';
11. Identify what each of the following escape sequences represents:
a.
b. \
c. "
d.
a. A newline character
b. A backslash character
c. A double quotation character
d. A tab character