* X more docs for C
[mascara-docs.git] / C / the.ansi.c.programming.language / notes.accompany.ansi.c / sx5c.html
blobd0752a24c3f57e562f3ac51ddf0e8a5970cbbcd2
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. -->
5 <html>
6 <head>
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>
13 </head>
14 <body>
15 <H2>section 2.3: Constants</H2>
17 page 37
18 <p>We write constants in decimal, octal, or hexadecimal
19 for our convenience,
20 not the compiler's.
21 The compiler doesn't care;
22 it always converts everything into binary internally, anyway.
23 (There is, however,
24 no good way to specify constants in source code in binary.)
25 </p><p>pages 37-38
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>)
42 appears to be.
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>
47 (that is,
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:
53 <pre> '0' == 48
54 '0' == '\060'
55 '0' == '\x30'
56 </pre>We'll have a bit more to say about characters
57 and their small integer representations
58 in section 2.7.
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>.
61 Also in section 2.7
62 we'll meet the <TT>atoi</TT> function
63 which computes a numeric value from a string of digits like this.
64 </p><p>page 39
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.
68 </p><hr>
69 <p>
70 Read sequentially:
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>
75 </p>
76 <p>
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>
80 </p>
81 </body>
82 </html>