Oid Display(Char *val){char Tmp[16];sprintf(Tmp, "Read Val: %sn", Val);puts(Tmp);}

In the C programming linguistic communication, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in grade of declarations for memory locations or variables. Information types also determine the types of operations or methods of processing of data elements.

The C linguistic communication provides basic arithmetic types, such as integer and existent number types, and syntax to build array and compound types. Headers for the C standard library, to exist used via include directives, comprise definitions of back up types, that take additional properties, such as providing storage with an exact size, independent of the language implementation on specific hardware platforms.[one] [ii]

Bones types [edit]

Primary types [edit]

The C language provides the four basic arithmetic type specifiers char, int, float and double, and the modifiers signed, unsigned, short, and long. The post-obit table lists the permissible combinations in specifying a large prepare of storage size-specific declarations.

Type Explanation Minimum size (bits) Format specifier Range Suffix for decimal constants
char Smallest addressable unit of measurement of the machine that can contain basic graphic symbol set up. It is an integer type. Bodily type tin be either signed or unsigned. It contains CHAR_BIT bits.[3] 8 %c CHAR_MIN / CHAR_MAX n/a
signed char Of the same size as char, but guaranteed to be signed. Capable of containing at least the [−127, +127] range.[3] [a] 8 %c (or %hhi for numerical output) SCHAR_MIN / SCHAR_MAX [5] due north/a
unsigned char Of the aforementioned size as char, but guaranteed to exist unsigned. Contains at least the [0, 255] range.[6] 8 %c (or %hhu for numerical output) 0 / UCHAR_MAX n/a
brusque
short int
signed short
signed short int
Brusk signed integer type. Capable of containing at least the [−32,767, +32,767] range.[3] [a] 16 %hi or %hd SHRT_MIN / SHRT_MAX northward/a
unsigned curt
unsigned short int
Brusk unsigned integer type. Contains at least the [0, 65,535] range.[three] 16 %hu 0 / USHRT_MAX n/a
int
signed
signed int
Bones signed integer type. Capable of containing at least the [−32,767, +32,767] range.[3] [a] 16 %i or %d INT_MIN / INT_MAX none
unsigned
unsigned int
Bones unsigned integer type. Contains at least the [0, 65,535] range.[3] 16 %u 0 / UINT_MAX u or U
long
long int
signed long
signed long int
Long signed integer type. Capable of containing at to the lowest degree the [−two,147,483,647, +2,147,483,647] range.[3] [a] 32 %li or %ld LONG_MIN / LONG_MAX l or L [7]
unsigned long
unsigned long int
Long unsigned integer type. Capable of containing at least the [0, 4,294,967,295] range.[3] 32 %lu 0 / ULONG_MAX both u or U and l or L
long long
long long int
signed long long
signed long long int
Long long signed integer type. Capable of containing at least the [−ix,223,372,036,854,775,807, +9,223,372,036,854,775,807] range.[iii] [a] Specified since the C99 version of the standard. 64 %lli or %lld LLONG_MIN / LLONG_MAX ll or LL
unsigned long long
unsigned long long int
Long long unsigned integer type. Contains at least the [0, +18,446,744,073,709,551,615] range.[three] Specified since the C99 version of the standard. 64 %llu 0 / ULLONG_MAX both u or U and ll or LL
bladder Real floating-point blazon, usually referred to as a single-precision floating-point type. Actual properties unspecified (except minimum limits); notwithstanding, on most systems, this is the IEEE 754 single-precision binary floating-point format (32 bits). This format is required past the optional Annex F "IEC 60559 floating-point arithmetic". Converting from text:[b]
  • %f %F
  • %thousand %G
  • %east %East
  • %a %A
double Real floating-point type, commonly referred to equally a double-precision floating-indicate type. Actual properties unspecified (except minimum limits); however, on nearly systems, this is the IEEE 754 double-precision binary floating-bespeak format (64 $.25). This format is required by the optional Addendum F "IEC 60559 floating-point arithmetic".
  • %lf %lF
  • %lg %lG
  • %le %lE
  • %la %lA [c]
long double Existent floating-point blazon, unremarkably mapped to an extended precision floating-point number format. Actual backdrop unspecified. It tin can be either x86 extended-precision floating-point format (80 bits, but typically 96 bits or 128 bits in memory with padding bytes), the non-IEEE "double-double" (128 $.25), IEEE 754 quadruple-precision floating-point format (128 bits), or the same as double. See the commodity on long double for details. %Lf %LF
%Lg %LG
%Le %LE
%La %LA [c]
  1. ^ a b c d due east The minimal ranges −(iin−ane−ane) to 2n−one−1 (east.grand. [−127,127]) come from the various integer representations allowed by the standard (ones' complement, sign-magnitude, two'south complement).[four] However, most platforms use 2's complement, implying a range of the form −2yard−1 to iiyard−1−ane with chiliad ≥ n for these implementations, eastward.k. [−128,127] (SCHAR_MIN = −128 and SCHAR_MAX = 127) for an viii-bit signed char.
  2. ^ These format strings also be for formatting to text, but operate on a double.
  3. ^ a b Uppercase differs from lowercase in the output. Capital specifiers produce values in the uppercase, and lowercase in lower (%A, %E, %F, %G produce such values as INF, NAN and East (exponent) in uppercase)

The actual size of the integer types varies past implementation. The standard requires only size relations between the data types and minimum sizes for each data type:

The relation requirements are that the long long is not smaller than long, which is not smaller than int, which is not smaller than brusque. As char'south size is always the minimum supported data type, no other information types (except fleck-fields) can be smaller.

The minimum size for char is 8 bits, the minimum size for brusque and int is 16 $.25, for long information technology is 32 bits and long long must contain at least 64 $.25.

The blazon int should exist the integer type that the target processor is about efficiently working with. This allows swell flexibility: for example, all types tin can be 64-bit. Nonetheless, several different integer width schemes (information models) are pop. Because the data model defines how different programs communicate, a compatible information model is used within a given operating organization awarding interface.[8]

In do, char is commonly 8 bits in size and curt is usually sixteen bits in size (every bit are their unsigned counterparts). This holds truthful for platforms as diverse every bit 1990s SunOS 4 Unix, Microsoft MS-DOS, modern Linux, and Microchip MCC18 for embedded eight-bit Pic microcontrollers. POSIX requires char to be exactly 8 $.25 in size.

Various rules in the C standard make unsigned char the basic type used for arrays suitable to store arbitrary non-bit-field objects: its lack of padding bits and trap representations, the definition of object representation,[6] and the possibility of aliasing.[9]

The actual size and behavior of floating-point types likewise vary by implementation. The simply guarantee is that long double is not smaller than double, which is not smaller than bladder. Commonly, the 32-bit and 64-bit IEEE 754 binary floating-point formats are used.

The C99 standard includes new real floating-point types float_t and double_t, defined in <math.h>. They correspond to the types used for the intermediate results of floating-bespeak expressions when FLT_EVAL_METHOD is 0, 1, or 2. These types may be wider than long double.

C99 also added complex types: bladder _Complex, double _Complex, long double _Complex.

Boolean blazon [edit]

C99 added a boolean (truthful/faux) blazon _Bool. Additionally, the <stdbool.h> header defines bool as a convenient alias for this type, and also provides macros for true and false. _Bool functions similarly to a normal integer blazon, with ane exception: any assignments to a _Bool that are non 0 (false) are stored as one (true). This behavior exists to avoid integer overflows in implicit narrowing conversions. For example, in the following code:

                        unsigned                                    char                                    b                                    =                                    256            ;                        if                                    (            b            )                                    {                                                /* practice something */                        }                      

Variable b evaluates to false if unsigned char has a size of viii bits. This is because the value 256 does not fit in the information type, which results in the lower eight $.25 of information technology being used, resulting in a zero value. Yet, changing the type causes the previous code to carry normally:

                        _Bool                                    b                                    =                                    256            ;                        if                                    (            b            )                                    {                                                /* do something */                        }                      

The blazon _Bool also ensures true values e'er compare equal to each other:

                        _Bool                                    a                                    =                                    1            ,                                    b                                    =                                    2            ;                        if                                    (            a                                    ==                                    b            )                                    {                                                /* practice something */                        }                      

Size and pointer departure types [edit]

The C linguistic communication specification includes the typedefs size_t and ptrdiff_t to represent memory-related quantities. Their size is defined according to the target processor's arithmetic capabilities, not the retentiveness capabilities, such as available accost space. Both of these types are divers in the <stddef.h> header (cstddef in C++).

size_t is an unsigned integer type used to correspond the size of any object (including arrays) in the item implementation. The operator sizeof yields a value of the blazon size_t. The maximum size of size_t is provided via SIZE_MAX, a macro constant which is defined in the <stdint.h> header (cstdint header in C++). size_t is guaranteed to be at least sixteen bits broad. Additionally, POSIX includes ssize_t, which is a signed integer type of the same width every bit size_t.

ptrdiff_t is a signed integer type used to represent the difference between pointers. It is guaranteed to exist valid only against pointers of the aforementioned type; subtraction of pointers consisting of unlike types is implementation-divers.

Interface to the backdrop of the basic types [edit]

Data about the actual properties, such as size, of the bones arithmetic types, is provided via macro constants in ii headers: <limits.h> header (climits header in C++) defines macros for integer types and <bladder.h> header (cfloat header in C++) defines macros for floating-point types. The actual values depend on the implementation.

Backdrop of integer types [edit]

  • CHAR_BIT – size of the char type in $.25 (at to the lowest degree 8 bits)
  • SCHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN (C99) – minimum possible value of signed integer types: signed char, signed short, signed int, signed long, signed long long
  • SCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX (C99) – maximum possible value of signed integer types: signed char, signed brusque, signed int, signed long, signed long long
  • UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX (C99) – maximum possible value of unsigned integer types: unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long
  • CHAR_MIN – minimum possible value of char
  • CHAR_MAX – maximum possible value of char
  • MB_LEN_MAX – maximum number of bytes in a multibyte character

Properties of floating-signal types [edit]

  • FLT_MIN, DBL_MIN, LDBL_MIN – minimum normalized positive value of float, double, long double respectively
  • FLT_TRUE_MIN, DBL_TRUE_MIN, LDBL_TRUE_MIN (C11) – minimum positive value of bladder, double, long double respectively
  • FLT_MAX, DBL_MAX, LDBL_MAX – maximum finite value of float, double, long double, respectively
  • FLT_ROUNDS – rounding mode for floating-point operations
  • FLT_EVAL_METHOD (C99) – evaluation method of expressions involving different floating-point types
  • FLT_RADIX – radix of the exponent in the floating-betoken types
  • FLT_DIG, DBL_DIG, LDBL_DIG – number of decimal digits that tin be represented without losing precision by bladder, double, long double, respectively
  • FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON – divergence between one.0 and the next representable value of float, double, long double, respectively
  • FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG – number of FLT_RADIX-base digits in the floating-point significand for types float, double, long double, respectively
  • FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP – minimum negative integer such that FLT_RADIX raised to a power one less than that number is a normalized float, double, long double, respectively
  • FLT_MIN_10_EXP, DBL_MIN_10_EXP, LDBL_MIN_10_EXP – minimum negative integer such that 10 raised to that ability is a normalized bladder, double, long double, respectively
  • FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP – maximum positive integer such that FLT_RADIX raised to a power 1 less than that number is a normalized bladder, double, long double, respectively
  • FLT_MAX_10_EXP, DBL_MAX_10_EXP, LDBL_MAX_10_EXP – maximum positive integer such that 10 raised to that power is a normalized float, double, long double, respectively
  • DECIMAL_DIG (C99) – minimum number of decimal digits such that any number of the widest supported floating-bespeak type can be represented in decimal with a precision of DECIMAL_DIG digits and read back in the original floating-point blazon without changing its value. DECIMAL_DIG is at least 10.

Fixed-width integer types [edit]

The C99 standard includes definitions of several new integer types to raise the portability of programs.[2] The already available basic integer types were accounted insufficient, because their actual sizes are implementation divers and may vary across different systems. The new types are especially useful in embedded environments where hardware usually supports only several types and that support varies betwixt different environments. All new types are defined in <inttypes.h> header (cinttypes header in C++) and besides are available at <stdint.h> header (cstdint header in C++). The types can be grouped into the following categories:

  • Exact-width integer types that are guaranteed to accept the aforementioned number north of $.25 across all implementations. Included only if information technology is available in the implementation.
  • Least-width integer types that are guaranteed to exist the smallest blazon bachelor in the implementation, that has at least specified number n of bits. Guaranteed to be specified for at least N=8,16,32,64.
  • Fastest integer types that are guaranteed to exist the fastest integer type available in the implementation, that has at least specified number n of bits. Guaranteed to be specified for at least Northward=8,16,32,64.
  • Pointer integer types that are guaranteed to exist able to agree a arrow. Included just if information technology is available in the implementation.
  • Maximum-width integer types that are guaranteed to be the largest integer type in the implementation.

The post-obit table summarizes the types and the interface to acquire the implementation details (n refers to the number of bits):

Type category Signed types Unsigned types
Blazon Minimum value Maximum value Type Minimum value Maximum value
Verbal width intn_t INTdue north_MIN INTn_MAX uintdue north_t 0 UINTn_MAX
Least width int_leastn_t INT_LEASTnorthward_MIN INT_LEASTn_MAX uint_leastn_t 0 UINT_LEASTn_MAX
Fastest int_fastdue north_t INT_FASTdue north_MIN INT_FASTn_MAX uint_fastn_t 0 UINT_FASTnorth_MAX
Pointer intptr_t INTPTR_MIN INTPTR_MAX uintptr_t 0 UINTPTR_MAX
Maximum width intmax_t INTMAX_MIN INTMAX_MAX uintmax_t 0 UINTMAX_MAX

Printf and scanf format specifiers [edit]

The <inttypes.h> header (cinttypes in C++) provides features that enhance the functionality of the types defined in the <stdint.h> header. Information technology defines macros for printf format cord and scanf format cord specifiers respective to the types defined in <stdint.h> and several functions for working with the intmax_t and uintmax_t types. This header was added in C99.

Printf format string

The macros are in the format PRI{fmt}{type} . Here {fmt} defines the output formatting and is 1 of d (decimal), x (hexadecimal), o (octal), u (unsigned) and i (integer). {blazon} defines the type of the argument and is one of n , FASTn , LEASTn , PTR, MAX, where n corresponds to the number of bits in the argument.

Scanf format cord

The macros are in the format SCN{fmt}{type} . Here {fmt} defines the output formatting and is one of d (decimal), x (hexadecimal), o (octal), u (unsigned) and i (integer). {type} defines the blazon of the argument and is one of n , FASTn , Leastn , PTR, MAX, where n corresponds to the number of bits in the argument.

Functions

Additional floating-point types [edit]

Similarly to the fixed-width integer types, ISO/IEC TS 18661 specifies floating-bespeak types for IEEE 754 interchange and extended formats in binary and decimal:

  • _FloatN for binary interchange formats;
  • _DecimalN for decimal interchange formats;
  • _FloatNx for binary extended formats;
  • _DecimalNorthward10 for decimal extended formats.

Structures [edit]

Structures aggregate the storage of multiple information items, of potentially differing data types, into i memory block referenced past a single variable. The following example declares the data type struct birthday which contains the name and birthday of a person. The structure definition is followed by a annunciation of the variable John that allocates the needed storage.

                        struct            birthday                                    {                                                char                                    name            [            20            ];                                                int                                    day            ;                                                int                                    month            ;                                                int                                    year            ;                        };                        struct            birthday                                    John            ;                      

The memory layout of a construction is a language implementation issue for each platform, with a few restrictions. The memory address of the first fellow member must be the same as the accost of structure itself. Structures may be initialized or assigned to using compound literals. A function may directly return a structure, although this is oftentimes not efficient at run-time. Since C99, a structure may likewise cease with a flexible assortment member.

A structure containing a arrow to a structure of its own blazon is commonly used to build linked data structures:

                        struct            node                                    {                                                int                                    val            ;                                                struct            node                                    *            adjacent            ;                        };                      

Arrays [edit]

For every blazon T, except void and part types, at that place be the types "array of N elements of type T". An assortment is a collection of values, all of the same type, stored contiguously in memory. An array of size N is indexed by integers from 0 up to and including N−ane. Here is a cursory example:

                        int                                    cat            [            x            ];                                    // array of 10 elements, each of type int          

Arrays can be initialized with a compound initializer, merely not assigned. Arrays are passed to functions past passing a pointer to the first element. Multidimensional arrays are defined every bit "array of array …", and all except the outermost dimension must have compile-time constant size:

                        int                                    a            [            ten            ][            8            ];                                    // array of 10 elements, each of type 'array of 8 int elements'          

Pointers [edit]

Every data type T has a corresponding type pointer to T . A pointer is a data type that contains the address of a storage location of a variable of a particular type. They are declared with the asterisk (*) type declarator following the basic storage type and preceding the variable proper noun. Whitespace earlier or after the asterisk is optional.

                        char                                    *            square            ;                        long                                    *            circle            ;                        int                                    *            oval            ;                      

Pointers may as well be declared for pointer information types, thus creating multiple indirect pointers, such as char ** and int ***, including pointers to assortment types. The latter are less common than an array of pointers, and their syntax may be confusing:

                        char                                    *            pc            [            10            ];                                    // array of ten elements of 'arrow to char'            char                                    (            *            pa            )[            x            ];                                    // pointer to a 10-chemical element assortment of char          

The element pc requires ten blocks of memory of the size of pointer to char (unremarkably 40 or 80 bytes on mutual platforms), but chemical element pa is just one arrow (size 4 or viii bytes), and the data it refers to is an array of ten bytes ( sizeof * pa == 10 ).

Unions [edit]

A union blazon is a special construct that permits access to the aforementioned retention block by using a selection of differing type descriptions. For example, a union of data types may be declared to allow reading the aforementioned data either as an integer, a float, or any other user alleged type:

                        marriage            {                                                int                                    i            ;                                                float                                    f            ;                                                struct            {                                                unsigned                                    int                                    u            ;                                                double                                    d            ;                                                }                                    s            ;                        }                                    u            ;                      

The total size of u is the size of u.s – which happens to be the sum of the sizes of usu and u.due south.d – since southward is larger than both i and f. When assigning something to u.i, some parts of u.f may be preserved if u.i is smaller than u.f.

Reading from a union member is not the same as casting since the value of the member is not converted, but merely read.

Part pointers [edit]

Function pointers allow referencing functions with a particular signature. For example, to store the address of the standard function abs in the variable my_int_f:

                        int                                    (            *            my_int_f            )(            int            )                                    =                                    &            abs            ;                        // the & operator can exist omitted, but makes clear that the "address of" abs is used here          

Role pointers are invoked by proper name only similar normal part calls. Function pointers are separate from pointers and void pointers.

Type qualifiers [edit]

The aforementioned types can exist characterized further past type qualifiers, yielding a qualified type. Equally of 2014[update] and C11, there are four type qualifiers in standard C: const (C89), volatile (C89), restrict (C99) and _Atomic (C11) – the latter has a individual proper noun to avert ambivalent with user names,[10] but the more ordinary name atomic can be used if the <stdatomic.h> header is included. Of these, const is by far the all-time-known and almost used, appearing in the standard library and encountered in any significant utilize of the C language, which must satisfy const-definiteness. The other qualifiers are used for low-level programming, and while widely used there, are rarely used past typical programmers.[ citation needed ]

Come across likewise [edit]

  • C syntax
  • Uninitialized variable
  • Integer (informatics)

References [edit]

  1. ^ Barr, Michael (2 December 2007). "Portable Stock-still-Width Integers in C". Retrieved xviii January 2016.
  2. ^ a b ISO/IEC 9899:1999 specification, TC3 (PDF). p. 255, § 7.eighteen Integer types <stdint.h>.
  3. ^ a b c d due east f one thousand h i j ISO/IEC 9899:1999 specification, TC3 (PDF). p. 22, § 5.2.four.2.i Sizes of integer types <limits.h>.
  4. ^ Rationale for International Standard—Programming Languages—C Revision 5.ten (PDF). p. 25, § 5.ii.4.ii.1 Sizes of integer types <limits.h>.
  5. ^ https://docs.microsoft.com/en-us/cpp/c-language/cpp-integer-limits?view=msvc-170.
  6. ^ a b ISO/IEC 9899:1999 specification, TC3 (PDF). p. 37, § 6.2.6.i Representations of types – General.
  7. ^ https://en.cppreference.com/west/cpp/language/integer_literal.
  8. ^ "64-Bit Programming Models: Why LP64?". The Open Group. Retrieved ix November 2011.
  9. ^ ISO/IEC 9899:1999 specification, TC3 (PDF). p. 67, § 6.five Expressions.
  10. ^ C11:The New C Standard, Thomas Plum

mclaughlinandareat.blogspot.com

Source: https://en.wikipedia.org/wiki/C_data_types

0 Response to "Oid Display(Char *val){char Tmp[16];sprintf(Tmp, "Read Val: %sn", Val);puts(Tmp);}"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel