source: public/doc/gnu-c/Integer-Constants.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 5.6 KB
Line 
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
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing 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<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.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>
60Next: <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> &nbsp; [<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,
68followed 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
72constant cannot start with the character &lsquo;<samp>0</samp>&rsquo; (zero) because
73that makes the constant octal.
74</p>
75<p>You can get the effect of a negative integer constant by putting a
76minus sign at the beginning. Grammatically speaking, that is an
77arithmetic expression rather than a constant, but it behaves just like
78a 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
82character &lsquo;<samp>0</samp>&rsquo; (zero), followed by any number of octal digits
83(&lsquo;<samp>0</samp>&rsquo; to &lsquo;<samp>7</samp>&rsquo;):
84</p>
85<div class="example">
86<pre class="example">0 // <span class="roman">zero</span>
87077 // <span class="roman">63</span>
880403 // <span class="roman">259</span>
89</pre></div>
90
91<p>Pedantically speaking, the constant <code>0</code> is an octal constant, but
92we can think of it as decimal; it has the same value either way.
93</p>
94<p>A hexadecimal constant starts with &lsquo;<samp>0x</samp>&rsquo; (upper or lower case)
95followed by hex digits (&lsquo;<samp>0</samp>&rsquo; to &lsquo;<samp>9</samp>&rsquo;, as well as &lsquo;<samp>a</samp>&rsquo;
96through &lsquo;<samp>f</samp>&rsquo; in upper or lower case):
97</p>
98<div class="example">
99<pre class="example">0xff // <span class="roman">255</span>
1000XA0 // <span class="roman">160</span>
1010xffFF // <span class="roman">65535</span>
102</pre></div>
103
104<span id="index-binary-integer-constants"></span>
105<p>A binary constant starts with &lsquo;<samp>0b</samp>&rsquo; (upper or lower case) followed
106by bits (each represented by the characters &lsquo;<samp>0</samp>&rsquo; or &lsquo;<samp>1</samp>&rsquo;):
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
115lexical confusion with the following tokens. See <a href="Invalid-Numbers.html">Invalid Numbers</a>.
116</p>
117<hr>
118<div class="header">
119<p>
120Next: <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> &nbsp; [<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>
Note: See TracBrowser for help on using the repository browser.