Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C syntax
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Integer types==== C's integer types come in different fixed sizes, capable of representing various ranges of numbers. The type {{code|char}} occupies exactly one [[byte]] (the smallest addressable storage unit), which is typically 8 bits wide. (Although {{code|char}} can represent any of C's "basic" characters, a wider type may be required for international character sets.) Most integer types have both [[signedness|signed and unsigned]] varieties, designated by the {{code|signed}} and {{code|unsigned}} keywords. Signed integer types always use the [[two's complement]] [[Signed number representations|representation]], since [[C23 (C standard revision)|C23]]<ref name="N2412">{{cite web |title=WG14-N2412: Two's complement sign representation |url=https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf |website=open-std.org |archive-url=https://web.archive.org/web/20221227174224/https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf |archive-date=December 27, 2022 |date=August 11, 2019 |url-status=live}}</ref> (and in practice before; in older C versions before C23 the representation might alternatively have been [[ones' complement]], or [[sign-and-magnitude]], but in practice that has not been the case for decades on modern hardware). In many cases, there are multiple equivalent ways to designate the type; for example, {{code|signed short int}} and {{code|short}} are synonymous. The representation of some types may include unused "padding" bits, which occupy storage but are not included in the width. The following table provides a complete list of the standard integer types and their ''minimum'' allowed widths (including any sign bit). {| class="wikitable" |+ Specifications for standard integer types |- ! Shortest form of specifier !! Minimum width (bits) |- | {{code|bool}} | style="text-align: center" | 1 |- | {{code|char}} | style="text-align: center" | 8 |- | {{code|signed char}} | style="text-align: center" | 8 |- | {{code|unsigned char}} | style="text-align: center" | 8 |- | {{code|short}} | style="text-align: center" | 16 |- | {{code|unsigned short}} | style="text-align: center" | 16 |- | {{code|int}} | style="text-align: center" | 16 |- | {{code|unsigned int}} | style="text-align: center" | 16 |- | {{code|long}} | style="text-align: center" | 32 |- | {{code|unsigned long}} | style="text-align: center" | 32 |- | {{code|long long}}<ref group="note" name="long long">The {{code|long long}} modifier was introduced in the [[C99]] standard.</ref> | style="text-align: center" | 64 |- | {{code|unsigned long long}}<ref group="note" name="long long"/> | style="text-align: center" | 64 |} The {{code|char}} type is distinct from both {{code|signed char}} and {{code|unsigned char}}, but is guaranteed to have the same representation as one of them. The {{code|_Bool}} and {{code|long long}} types are standardized since 1999, and may not be supported by older C compilers. Type {{code|_Bool}} is usually accessed via the <code>[[typedef]]</code> name {{code|bool}} defined by the standard header <code><[[stdbool.h]]></code>, however since C23 the {{code|_Bool}} type has been renamed {{code|bool}}, and <code><stdbool.h></code> has been deprecated. In general, the widths and representation scheme implemented for any given platform are chosen based on the machine architecture, with some consideration given to the ease of importing source code developed for other platforms. The width of the {{code|int}} type varies especially widely among C implementations; it often corresponds to the most "natural" word size for the specific platform. The standard header [[limits.h]] defines macros for the minimum and maximum representable values of the standard integer types as implemented on any specific platform. In addition to the standard integer types, there may be other "extended" integer types, which can be used for {{code|typedef}}s in standard headers. For more precise specification of width, programmers can and should use {{code|typedef}}s from the standard header [[stdint.h]]. Integer constants may be specified in source code in several ways. Numeric values can be specified as [[decimal]] (example: {{code|1022}}), [[octal]] with zero ({{code|0}}) as a prefix ({{code|01776}}), or [[hexadecimal]] with {{code|0x}} (zero x) as a prefix ({{code|0x3FE}}). A character in single quotes (example: {{code|'R'}}), called a "character constant," represents the value of that character in the execution character set, with type {{code|int}}. Except for character constants, the type of an integer constant is determined by the width required to represent the specified value, but is always at least as wide as {{code|int}}. This can be overridden by appending an explicit length and/or signedness modifier; for example, {{code|12lu}} has type {{code|unsigned long}}. There are no negative integer constants, but the same effect can often be obtained by using a unary negation operator "{{code|-}}".
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)