1 <!DOCTYPE HTML PUBLIC
"-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995, 1996 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
7 <link rev=
"owner" href=
"mailto:scs@eskimo.com">
8 <link rev=
"made" href=
"mailto:scs@eskimo.com">
9 <title>section
2.3: Constants
</title>
10 <link href=
"sx5b.html" rev=precedes
>
11 <link href=
"sx5d.html" rel=precedes
>
12 <link href=
"sx5.html" rev=subdocument
>
15 <H2>section
2.3: Constants
</H2>
18 <p>We write constants in decimal, octal, or hexadecimal
21 The compiler doesn't care;
22 it always converts everything into binary internally, anyway.
24 no good way to specify constants in source code in binary.)
26 </p><p>Read the descriptions of character and string constants carefully;
27 most C programs work with these data types a lot,
28 and their proper use must be kept in mind.
29 Note particularly these facts:
30 </p><OL><li>The character constant
<TT>'x'
</TT> is quite different from
31 the string constant
<TT>"x"</TT>.
32 <li>The value of a character is simply
33 ``the numeric value of the character in the machine's character set.''
35 <li>Strings are terminated by the null character,
<TT>\
0</TT>.
36 (This applies to both string constants and to all other strings
37 we'll build and manipulate.)
38 This means that the size of a string
39 (the number of
<TT>char
</TT>'s worth of memory it occupies)
40 is always one more than its length
41 (i.e. as reported by
<TT>strlen
</TT>)
43 </OL><p>As we saw in section
1.6 on page
23,
44 it's possible to switch rather freely between thinking of a
45 character as a character and thinking of it as its value.
46 For example, the
<em>character
</em> <TT>'
0'
</TT>
48 the character that can print on your screen
49 and looks like the number zero)
50 has in the ASCII character set the internal
<em>value
</em> 48.
51 Another way of saying this is to notice that the following
52 expressions are all true:
56 </pre>We'll have a bit more to say about characters
57 and their small integer representations
59 </p><p>Note also that the
<em>string
</em> <TT>"48"</TT> consists of the
60 three characters
<TT>'
4'
</TT>,
<TT>'
8'
</TT>, and
<TT>'\
0'
</TT>.
62 we'll meet the
<TT>atoi
</TT> function
63 which computes a numeric value from a string of digits like this.
65 </p><p>We won't be using enumerations,
66 so you don't have to worry too much about the description of
67 enumeration constants.
71 <a href=
"sx5b.html" rev=precedes
>prev
</a>
72 <a href=
"sx5d.html" rel=precedes
>next
</a>
73 <a href=
"sx5.html" rev=subdocument
>up
</a>
74 <a href=
"top.html">top
</a>
77 This page by
<a href=
"http://www.eskimo.com/~scs/">Steve Summit
</a>
78 //
<a href=
"copyright.html">Copyright
</a> 1995,
1996
79 //
<a href=
"mailto:scs@eskimo.com">mail feedback
</a>