* remove "\r" nonsense
[mascara-docs.git] / C / the.ansi.c.programming.language / c.programming.notes / sx2.html
blob3c5140396448630d60edfcec790cbbbeeec4695a
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>Chapter 2: Basic Data Types and Operators</title>
10 <link href="sx1c.html" rev=precedes>
11 <link href="sx2a.html" rel=precedes>
12 <link href="top.html" rev=subdocument>
13 </head>
14 <body>
15 <H1>Chapter 2: Basic Data Types and Operators</H1>
17 <p>The <dfn>type</dfn> of a variable
18 determines what kinds of values it may take on.
19 An <dfn>operator</dfn> computes new values out of old ones.
20 An <dfn>expression</dfn> consists of variables, constants, and
21 operators combined to perform some useful computation.
22 In this chapter, we'll learn about C's basic types,
23 how to
24 write constants and
25 declare variables of these types,
26 and
27 what the basic operators are.
28 </p><p>As Kernighan and Ritchie say,
29 ``The type of an object determines the set of values it can have
30 and what operations can be performed on it.''
31 This is a fairly formal, mathematical definition of what a type is,
32 but it is traditional (and meaningful).
33 There are several implications to remember:
34 <OL><li>The ``set of values'' is
35 finite.
36 C's <TT>int</TT> type can not represent <em>all</em> of the integers;
37 its <TT>float</TT> type can not represent <em>all</em>
38 floating-point numbers.
39 <li>When you're using an object (that is, a variable) of some type,
40 you
41 may
42 have to remember what values it can take on and what
43 operations you can perform on it.
44 For example,
45 there are several operators which
46 play with
48 the binary (bit-level) representation of integers,
49 but these operators
50 are not meaningful for
51 and may not be applied to
52 floating-point operands.
53 <li>When declaring a new variable and picking a type for it,
54 you have to keep in mind the values and operations you'll be needing.
55 </OL>In other words,
56 picking a type for a variable is not some abstract academic exercise;
57 it's closely
58 connected
59 to the way(s) you'll be using that variable.
60 </p><p><a href="sx2a.html" rel=subdocument>2.1 Types</a></p>
61 <p><a href="sx2b.html" rel=subdocument>2.2 Constants</a></p>
62 <p><a href="sx2c.html" rel=subdocument>2.3 Declarations</a></p>
63 <p><a href="sx2d.html" rel=subdocument>2.4 Variable Names</a></p>
64 <p><a href="sx2e.html" rel=subdocument>2.5 Arithmetic Operators</a></p>
65 <p><a href="sx2f.html" rel=subdocument>2.6 Assignment Operators</a></p>
66 <p><a href="sx2g.html" rel=subdocument>2.7 Function Calls</a></p>
67 <hr>
68 <p>
69 Read sequentially:
70 <a href="sx1c.html" rev=precedes>prev</a>
71 <a href="sx2a.html" rel=precedes>next</a>
72 <a href="top.html" rev=subdocument>up</a>
73 <a href="top.html">top</a>
74 </p>
75 <p>
76 This page by <a href="http://www.eskimo.com/~scs/">Steve Summit</a>
77 // <a href="copyright.html">Copyright</a> 1995, 1996
78 // <a href="mailto:scs@eskimo.com">mail feedback</a>
79 </p>
80 </body>
81 </html>