1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Integer Constants (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Integer Constants (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Integer Constants (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="Constants.html" rel="up" title="Constants">
|
---|
33 | <link href="Integer-Const-Type.html" rel="next" title="Integer Const Type">
|
---|
34 | <link href="Constants.html" rel="prev" title="Constants">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Integer-Constants"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Integer-Const-Type.html" accesskey="n" rel="next">Integer Const Type</a>, Up: <a href="Constants.html" accesskey="u" rel="up">Constants</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Integer-Constants-1"></span><h3 class="section">12.1 Integer Constants</h3>
|
---|
64 | <span id="index-integer-constants"></span>
|
---|
65 | <span id="index-constants_002c-integer"></span>
|
---|
66 |
|
---|
67 | <p>An integer constant consists of a number to specify the value,
|
---|
68 | followed optionally by suffix letters to specify the data type.
|
---|
69 | </p>
|
---|
70 | <p>The simplest integer constants are numbers written in base 10
|
---|
71 | (decimal), such as <code>5</code>, <code>77</code>, and <code>403</code>. A decimal
|
---|
72 | constant cannot start with the character ‘<samp>0</samp>’ (zero) because
|
---|
73 | that makes the constant octal.
|
---|
74 | </p>
|
---|
75 | <p>You can get the effect of a negative integer constant by putting a
|
---|
76 | minus sign at the beginning. Grammatically speaking, that is an
|
---|
77 | arithmetic expression rather than a constant, but it behaves just like
|
---|
78 | a true constant.
|
---|
79 | </p>
|
---|
80 | <p>Integer constants can also be written in octal (base 8), hexadecimal
|
---|
81 | (base 16), or binary (base 2). An octal constant starts with the
|
---|
82 | character ‘<samp>0</samp>’ (zero), followed by any number of octal digits
|
---|
83 | (‘<samp>0</samp>’ to ‘<samp>7</samp>’):
|
---|
84 | </p>
|
---|
85 | <div class="example">
|
---|
86 | <pre class="example">0 // <span class="roman">zero</span>
|
---|
87 | 077 // <span class="roman">63</span>
|
---|
88 | 0403 // <span class="roman">259</span>
|
---|
89 | </pre></div>
|
---|
90 |
|
---|
91 | <p>Pedantically speaking, the constant <code>0</code> is an octal constant, but
|
---|
92 | we can think of it as decimal; it has the same value either way.
|
---|
93 | </p>
|
---|
94 | <p>A hexadecimal constant starts with ‘<samp>0x</samp>’ (upper or lower case)
|
---|
95 | followed by hex digits (‘<samp>0</samp>’ to ‘<samp>9</samp>’, as well as ‘<samp>a</samp>’
|
---|
96 | through ‘<samp>f</samp>’ in upper or lower case):
|
---|
97 | </p>
|
---|
98 | <div class="example">
|
---|
99 | <pre class="example">0xff // <span class="roman">255</span>
|
---|
100 | 0XA0 // <span class="roman">160</span>
|
---|
101 | 0xffFF // <span class="roman">65535</span>
|
---|
102 | </pre></div>
|
---|
103 |
|
---|
104 | <span id="index-binary-integer-constants"></span>
|
---|
105 | <p>A binary constant starts with ‘<samp>0b</samp>’ (upper or lower case) followed
|
---|
106 | by bits (each represented by the characters ‘<samp>0</samp>’ or ‘<samp>1</samp>’):
|
---|
107 | </p>
|
---|
108 | <div class="example">
|
---|
109 | <pre class="example">0b101 // <span class="roman">5</span>
|
---|
110 | </pre></div>
|
---|
111 |
|
---|
112 | <p>Binary constants are a GNU C extension, not part of the C standard.
|
---|
113 | </p>
|
---|
114 | <p>Sometimes a space is needed after an integer constant to avoid
|
---|
115 | lexical confusion with the following tokens. See <a href="Invalid-Numbers.html">Invalid Numbers</a>.
|
---|
116 | </p>
|
---|
117 | <hr>
|
---|
118 | <div class="header">
|
---|
119 | <p>
|
---|
120 | Next: <a href="Integer-Const-Type.html" accesskey="n" rel="next">Integer Const Type</a>, Up: <a href="Constants.html" accesskey="u" rel="up">Constants</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
121 | </div>
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 | </body>
|
---|
126 | </html>
|
---|