section 2.3: Constants
page 37
We write constants in decimal, octal, or hexadecimal for our convenience, not the compiler's. The compiler doesn't care; it always converts everything into binary internally, anyway. (There is, however, no good way to specify constants in source code in binary.) pages 37-38
Read the descriptions of character and string constants carefully; most C programs work with these data types a lot, and their proper use must be kept in mind. Note particularly these facts:
- The character constant 'x' is quite different from the string constant "x".
- The value of a character is simply ``the numeric value of the character in the machine's character set.''
- Strings are terminated by the null character, \0. (This applies to both string constants and to all other strings we'll build and manipulate.) This means that the size of a string (the number of char's worth of memory it occupies) is always one more than its length (i.e. as reported by strlen) appears to be.
'0' == 48 '0' == '\060' '0' == '\x30'We'll have a bit more to say about characters and their small integer representations in section 2.7.
Note also that the string "48" consists of the three characters '4', '8', and '\0'. Also in section 2.7 we'll meet the atoi function which computes a numeric value from a string of digits like this. page 39
We won't be using enumerations, so you don't have to worry too much about the description of enumeration constants.
No comments:
Post a Comment