The fact that I've found 6 errors in the first 50 pages of the text book, might suggest that my confusion is the book's fault, but here we go.
1)
The book explains that dividing by negative integers, e.g., 16/-3, results in varying values, depending on the compiler and should be avoided; all other examples in the problem set where the denominator is negative are considered 'invalid.'
If
where y= -1.0, why does the textbook list the answer to the expression
as -3.14159?
I know that PI is a character string, not an int. Is that why the value is -3.14159?
2) In the following:
The text book describes '&' as the address-of operator, which tell the scanf function where to find each variable in memory into which the new value will be stored. If '&' is omitted scanf would know only the variable's current value, not its location in memory, which would prevent scanf from storing a new value.
Can someone explain in more detail? I understand what '&' is doing, but not how. (It's possible that this might be a question I just won't understand now, so that's OK if that's the case.)
3) The book also says the following about scanf:
"If you type more data characters on a line than are needed by the current call to scanf, the extra characters will be processed by the next call to scanf."
The book seems to be implying that extra characters somehow hang around (in memory?) until the next call to scanf. It makes no sense to me that these orphan characters would somehow be processed by the very next call to scanf, regardless of what else I might be specifying as input for the next call.
Can someone clarify what happens to extraneous characters if they aren't processed in the current function call?
Thanks.
1)
The book explains that dividing by negative integers, e.g., 16/-3, results in varying values, depending on the compiler and should be avoided; all other examples in the problem set where the denominator is negative are considered 'invalid.'
If
Code:
#define PI 3.14159
...
double x, y;
...
where y= -1.0, why does the textbook list the answer to the expression
Code:
x = PI / Y;
as -3.14159?
I know that PI is a character string, not an int. Is that why the value is -3.14159?
2) In the following:
Code:
scanf("%lf", &miles);
The text book describes '&' as the address-of operator, which tell the scanf function where to find each variable in memory into which the new value will be stored. If '&' is omitted scanf would know only the variable's current value, not its location in memory, which would prevent scanf from storing a new value.
Can someone explain in more detail? I understand what '&' is doing, but not how. (It's possible that this might be a question I just won't understand now, so that's OK if that's the case.)
3) The book also says the following about scanf:
"If you type more data characters on a line than are needed by the current call to scanf, the extra characters will be processed by the next call to scanf."
The book seems to be implying that extra characters somehow hang around (in memory?) until the next call to scanf. It makes no sense to me that these orphan characters would somehow be processed by the very next call to scanf, regardless of what else I might be specifying as input for the next call.
Can someone clarify what happens to extraneous characters if they aren't processed in the current function call?
Thanks.