Solution Manual For A First Book of C 4th Edition
Solution Manual For A First Book of C 4th Edition
Solution Manual For A First Book of C 4th Edition
1. The value stored in the variable total, the number of bytes reserved for the
variable, and where these bytes are located in memory.
2. &average means the address of the variable named average.
3. The address of a variable is always its starting location, so the addresses are as
follows:
&temp is 16892
&dist is 16896
&date is 16900
&miles is 16908
4.
a. See solution file pgm8-1ex4a.cpp.
b. Answers will vary.
c. See solution file pgm8-1ex4c.cpp. The output indicates that storage for each
variable was allocated in the order the variables were declared. In almost all
cases, variables are stored starting at a word boundary. That is, if the computer
has a 32-bit word (4 bytes), each variable is stored starting at the beginning of
the 4 bytes defining a word.
5. An address is stored in a pointer.
6.
a. *xAddr
b. *yAddr
c. *ptYld
d. *ptMiles
e. *mptr
f. *pdate
g. *distPtr
h. *tabPt
i. *hoursPt
7.
a. int *yAddr;
b. char *chAddr;
Exercises 8.2
1.
a. *(prices + 5)
b. *(grades + 2)
c. *(yield + 10)
d. *(dist + 9)
e. *mile
f. *(temp + 20)
g. *(celsius + 16)
h. *(num + 50)
i. *(time + 12)
2.
a. message[6]
b. amount[0]
c. yrs[10]
d. stocks[2]
e. rates[15]
f. codes[19]
3.
a. The declaration double prices[5]; causes storage space for five double-
precision numbers, creates a pointer constant named prices, and equates the
pointer constant to the address of the first element (&prices[0]).
b. Each element in prices contains 8 bytes and there are five elements, for a total
of 40 bytes.
c. prices
&prices[0]
prices[0] or prices[1] or
*prices *(prices + 1)
prices[3] or prices[4] or
*(prices + 3) *(prices + 4)
prices[5] or
*(prices + 5)
d. The byte offset for this element from the beginning of the array is 3 * 8 = 24
bytes.
4.
a. See solution file pgm8-2ex4a.cpp.
b. See solution file pgm8-2ex4b.cpp.
5. See solution file pgm8-2ex5.cpp.
6.
a. See solution file pgm8-2ex6a.cpp.
b. See solution file pgm8-2ex6b.cpp.
7. See solution file pgm8-2ex7.cpp.
8. See solution file pgm8-2ex8.cpp.
Exercises 8.3
Exercises 8.4
1.
void sortArray(double inArray[500])
void sortArray(double inArray[])
void sortArray(double *inArray)
2.
void findKey(char select[256])
void findKey(char select[])
void findKey(char *select)
3.
double maximum(double speed[100])
double maximum (double speed[])
double maximum (double * speed)
4.
int findMin(int *vals, int numels)
{
int i, min = *vals++;
return;
}
10. The function is written as follows and tested in solution file pgm8-4ex10.cpp:
void trimrear(char *strng)
{
char * strng2;
strng2 = strng; // store the starting address
return;
}
11. See solution file pgm8-4ex11.cpp.
12. The output is as follows:
33
16
99
34
This is why:
*(*val) = *(val[0]) = val[0][0] = 33;
*(*val + 1) = *(val[1]) = val[1][0] = 16;
*(*(val + 1) + 2) = *(*(val[1]) + 2) = *(val[1][2]) = 99;
*(*val) + 1 = *(val[0]) + 1 = val[0][0] + 1 = 33 + 1 = 34;
Solution Manual for A Firstof C++, 4th Edition