|
|
Line 1: |
Line 1: |
| {{C Standard Library}}
| | One of many greatest reasons investing in a Singapore new launch is an efficient issues is as a result of it is attainable to be lent giant amounts of money at very low interest rates that you should use to buy it. Then, if property values continue to go up, then you will get a really excessive return on investment (ROI). Just be certain you purchase one of the better properties, comparable to the ones at Fernvale the Riverbank or any Singapore landed property Get Revenue through Renting<br><br>It displays how a lot Samsung is agonizing to secure margins. They're now providing premium fashions at decrease prices because the demand outlook for high-end telephones remains uncertain," said Lee Seung-woo, an analyst at IBK Securities. To make certain, Samsung has a far broader product line-up than rival Apple, and it has some leeway to trim costs given that manufacturing costs have fallen. Lee Min-hee, an analyst at IM Funding, reckons the entire value of manufacturing supplies for the S5 - from the battery and display to the processor and sensors - shall be 10-15 % decrease than for the S4. Within walking instance to approaching Stevens MRT Station on days you want to leave your car at house.<br><br>Punggol Ec Govt Condominium Website at Punggol Area Stroll / Punggol East has awarded the tender bid to the highest bidder Sing Holdings Limited, at the tender worth of $162.1 million on 10 Dec 2012.This New Punggol EC is inside 3 minutes walk to Coral Edge LRT and minutes to the Punggol MRT and Bus Interchange. Click to View Waterwoods The Panorama Rental is unquestionably an accessible place; there can be two choices, the Ang Mo Kio MRT Station as well as Ang Mo Kio Bus Interchange. Additionally, the Central Expressway (CTE) is near The Panorama Condo. There are prestigious faculties resembling CHIJ St Nicholas, Ai Tong and Kuo Chuan Presbyterian in the vicinity. Bishan Park, Lower Pierce Reservoir & Yio Chu Kang Stadium are additionally easily accessible to The Panorama Condominium<br><br>Buying a apartment in Singapore isn't one thing onerous or one thing that solely privileged people can do. You can have your individual residential unit by way of the numerous new launch property ads discovered on the Internet and also by way of newspaper ads. With these media infomercials, you will be up to date with new tasks developed by Singapore's first-class builders. Currently we now have a comprehensive checklist of obtainable new property launch residential condos or residences and landed homes in Singapore below and we hope the information information featured in each web page is sufficient so that you can purchase for own residing or investment objective. N ew Rental Urban Vista Tanah Merah Launch 2013 Buyers do NOT, and may NOT, must pay any agent any payment, when shopping for property in Singapore.<br><br>Marine Blue condo is a Freehold new launch rental development by Capitaland (One in all Singapore largest developer) in the very wanted space of Marine Parade in District 15. Marine Blue apartment is positioned mins away from Parkway Parade and in addition strolling distance to East Coast Park! With estimated completion in mid 2018, it'll comprise of 124 units of varied sizes and layouts. Marine Blue apartment residents may also be capable of entry within a brief drive to Siglap, Bedok City Centre and even the Kallang Riverside park which is a brief distance away for some household fun and gatherings. A wholesome fun-crammed life-style awaits you at Marine Blue<br><br>In actual fact, things can get fairly chaotic, with consumers clamouring to be the primary to ebook their models. For some Singapore property sales, there may even be in a single day queues. To avoid that, builders may choose to make use of balloting instead of queueing for figuring out who gets to enter the showflat first. Look through the unit plans and decide what unit kind you would like. A value psf (per square foot) range is normally offered so that you'd be able to estimate a rough price for each unit sort. (You may want to use the mortgage calculator on the correct of this web page to figure out the instalments payable for getting property in Singapore.) Continuereading The Tembusu Kovan upcoming launch by Wing Tai" But how are you going to find the proper property for you? Ecopolitan EC<br><br>Singapore is also rated as a prime place on the planet for residing, working and taking part in. It is globally linked, has multiple cultures dwelling there, and is a great environment with many industries and companies. There's a strong [http://xrandi.com/index.php?m=member_blog&p=view&id=7672&sid=2624 Download the skywoods] legal system, properties are close to the place you're employed or to entertainment, and it has been stated by the International Competitiveness Report that Singapore is ranked as one of the crucial aggressive Asia countries in the world and is within the high three in overseas trade and funding.<br><br>These are the principle issues you have to be considering when looking for family items within the number of selections from the numerous Singapore property developments. Inside the country, there are numerous new apartment launch events by world-renowned developers from the nation which are held within the island to show new residential developments to potential residents. These occasions won't solely enable you to in understanding additional about the advantages of investing on new condominiums which might be in the strategy of being constructed and available in the coming years, but also give you a new mild in seeing why shopping for Singapore apartment is the higher choice. |
| | |
| In the [[C (programming language)|C programming language]], '''data types''' refers to an extensive system for declaring variables of different types. The language itself provides basic arithmetic types and syntax to build array and compound types. Several headers in the [[C standard library|standard library]] contain definitions of support types, that have additional properties, such as exact size, guaranteed.<ref>{{cite web | url=http://www.netrino.com/node/140 | title=Portable Fixed-Width Integers in C | first=Michael | last=Barr | date=2 December 2007 | accessdate=8 November 2011}}</ref><ref name=c99>{{cite book | url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf | title=ISO/IEC 9899:1999 specification | at=p. 264, § 7.18 ''Integer types''}}</ref>
| |
| | |
| ==Basic types==
| |
| | |
| The C language provides many basic types. Most of them are formed from one of the four basic arithmetic type specifiers in C (<code>char</code>, <code>int</code>, <code>float</code> and <code>double</code>), and optional specifiers (<code>signed</code>, <code>unsigned</code>, <code>short</code>, <code>long</code>). All available basic arithmetic types are listed below:
| |
| | |
| {| class="wikitable" style="font-size:0.90em; line-height:1.3em;"
| |
| |-
| |
| ! style="width:14em;"| Type
| |
| !| Explanation
| |
| |-
| |
| || {{cpp|char}} || smallest addressable unit of the machine that can contain basic character set. It is an integer type. Actual type can be either signed or unsigned depending on the implementation.
| |
| |-
| |
| || {{cpp|signed char}} || same size as <code>char</code>, but guaranteed to be signed.
| |
| |-
| |
| | {{cpp|unsigned char}} || same size as <code>char</code>, but guaranteed to be unsigned.
| |
| |-
| |
| | {{cpp|short}}<br>{{cpp|short int}}<br>{{cpp|signed short}}<br>{{cpp|signed short int}} || ''short'' signed integer type. At least 16 bits in size.
| |
| |-
| |
| | {{cpp|unsigned short}}<br>{{cpp|unsigned short int}} || same as <code>short</code>, but unsigned.
| |
| |-
| |
| | {{cpp|int}}<br>{{cpp|signed int}} || basic signed integer type. At least 16 bits in size.
| |
| |-
| |
| | {{cpp|unsigned}}<br>{{cpp|unsigned int}} || same as <code>int</code>, but unsigned.
| |
| |-
| |
| | {{cpp|long}}<br>{{cpp|long int}}<br>{{cpp|signed long}}<br>{{cpp|signed long int}} || ''long'' signed integer type. At least 32 bits in size.
| |
| |-
| |
| | {{cpp|unsigned long}}<br>{{cpp|unsigned long int}} || same as <code>long</code>, but unsigned.
| |
| |-
| |
| | {{cpp|long long}}<br>{{cpp|long long int}}<br>{{cpp|signed long long}}<br>{{cpp|signed long long int}} || ''long long'' signed integer type. At least 64 bits in size. Specified since the [[C99]] version of the standard.
| |
| |-
| |
| | {{cpp|unsigned long long}}<br>{{cpp|unsigned long long int}} || same as <code>long long</code>, but unsigned. Specified since the [[C99]] version of the standard.
| |
| |-
| |
| | {{cpp|float}} || single precision floating-point type. Actual properties unspecified (except minimum limits), however on most systems this is the [[Single-precision floating-point format|IEEE 754 single-precision binary floating-point format]]. This format is required by the optional Annex F "IEC 60559 floating-point arithmetic".
| |
| |-
| |
| | {{cpp|double}} || double precision floating-point type. Actual properties unspecified (except minimum limits), however on most systems this is the [[Double-precision floating-point format|IEEE 754 double-precision binary floating-point format]]. This format is required by the optional Annex F "IEC 60559 floating-point arithmetic".
| |
| |-
| |
| | {{cpp|long double}} || extended precision floating-point type. Actual properties unspecified. Unlike types {{cpp|float}} and {{cpp|double}}, it can be either [[Extended precision|80-bit floating point format]], the non-IEEE "double-double" or [[Quadruple-precision floating-point format|IEEE 754 quadruple-precision floating-point format]] if a higher precision format is provided, otherwise it is the same as {{cpp|double}}. See [[long double|the article on long double]] for details.
| |
| |}
| |
| | |
| The actual size of integer types varies by implementation. The standard only requires size relations between the data types and minimum sizes for each data type:
| |
| | |
| The relation requirements are that the <code>long long</code> is not smaller than <code>long</code>, which is not smaller than <code>int</code>, which is not smaller than <code>short</code>. As <code>char</code>'s size is always the minimum supported data type, all other data types can't be smaller.
| |
| | |
| The minimum size for <code>char</code> is 8 bit, the minimum size for <code>short</code> and <code>int</code> is 16 bit, for <code>long</code> it is 32 bit and <code>long long</code> must contain at least 64 bit.
| |
| | |
| The type <code>int</code> should be the integer type that the target processor is most efficient working with. This allows great flexibility: for example, all types can be 64-bit. However, several different integer width schemes (data models) are popular. This is because the data model defines how different programs communicate, a uniform data model is used within a given operating system application interface.<ref>{{cite web|url=http://www.unix.org/version2/whatsnew/lp64_wp.html | title=64-Bit Programming Models: Why LP64? |publisher=The Open Group | accessdate=9 November 2011}}</ref>
| |
| | |
| In practice it should be noted that <code>char</code> is usually 8 bits in size and <code>short</code> is usually 16 bits in size (as are their unsigned counterparts). This holds true for platforms as diverse as 1990s [[SunOS]] 4 Unix, Microsoft [[MS-DOS]], modern [[Linux]], and Microchip MCC18 for embedded 8 bit PIC microcontrollers. [[POSIX]] requires <code>char</code> to be exactly 8 bits in size.
| |
| | |
| The actual size and behavior of floating-point types also vary by implementation. The only guarantee is that <code>long double</code> is not smaller than <code>double</code>, which is not smaller than <code>float</code>. Usually, the 32-bit and 64-bit [[IEEE floating point|IEEE 754]] binary floating-point formats are used, if supported by hardware.
| |
| | |
| ==={{anchor|stdbool.h}}Boolean type===
| |
| [[C99]] added a boolean (true/false) type (<code>_Bool</code>) which is defined in the <code><stdbool.h></code> header. Additionally, the standard requires that macros are defined to alias the type as <code>bool</code> as well as providing macros for <code>true</code> and <code>false</code>.
| |
| | |
| ==={{anchor|stddef.h}}Size and pointer difference types===
| |
| | |
| The C language provides the separate types <code>size_t</code> and <code>ptrdiff_t</code> to represent memory-related quantities. Existing types were deemed insufficient, because their size is defined according to the target processor's arithmetic capabilities, not the memory capabilities, such as available address space. Both of these types are defined in the <code><stddef.h></code> header (<code>cstddef</code> header in C++).
| |
| | |
| <code>size_t</code> is used to represent the size of any object (including arrays) in the particular implementation. It is used as the return type of the <code>sizeof</code> operator. The maximum size of <code>size_t</code> is provided via <code>SIZE_MAX</code>, a macro constant which is defined in the <code><stdint.h></code> header (<code>cstdint</code> header in C++). It is guaranteed to be at least 65535.
| |
| | |
| Note that <code>size_t</code> is unsigned, signed sizes can be represented by <code>ssize_t</code>.
| |
| | |
| <code>ptrdiff_t</code> is used to represent the difference between pointers.
| |
| | |
| ==={{anchor|limits.h|float.h}}Interface to the properties of the basic types===
| |
| | |
| Information about the actual properties, such as size, of the basic arithmetic types, is provided via macro constants in two headers: <code><limits.h></code> header (<code>climits</code> header in C++) defines macros for integer types and <code><float.h></code> header (<code>cfloat</code> header in C++) defines macros for floating-point types. The actual values depend on the implementation.
| |
| | |
| ; Properties of integer types
| |
| *<code>CHAR_BIT</code> – size of the {{cpp|char}} type in bits (at least 8 bits)
| |
| *<code>SCHAR_MIN</code>, <code>SHRT_MIN</code>, <code>INT_MIN</code>, <code>LONG_MIN</code>, <code>LLONG_MIN</code><small>(C99)</small> – minimum possible value of signed integer types: {{cpp|signed char}}, {{cpp|signed short}}, {{cpp|signed int}}, {{cpp|signed long}}, {{cpp|signed long long}}
| |
| *<code>SCHAR_MAX</code>, <code>SHRT_MAX</code>, <code>INT_MAX</code>, <code>LONG_MAX</code>, <code>LLONG_MAX</code><small>(C99)</small> – maximum possible value of signed integer types: {{cpp|signed char}}, {{cpp|signed short}}, {{cpp|signed int}}, {{cpp|signed long}}, {{cpp|signed long long}}
| |
| *<code>UCHAR_MAX</code>, <code>USHRT_MAX</code>, <code>UINT_MAX</code>, <code>ULONG_MAX</code>, <code>ULLONG_MAX</code><small>(C99)</small> – maximum possible value of unsigned integer types: {{cpp|unsigned char}}, {{cpp|unsigned short}}, {{cpp|unsigned int}}, {{cpp|unsigned long}}, {{cpp|unsigned long long}}
| |
| *<code>CHAR_MIN</code> – minimum possible value of {{cpp|char}}
| |
| *<code>CHAR_MAX</code> – maximum possible value of {{cpp|char}}
| |
| *<code>MB_LEN_MAX</code> – maximum number of bytes in a multibyte character
| |
| | |
| ; Properties of floating-point types
| |
| *<code>FLT_MIN</code>, <code>DBL_MIN</code>, <code>LDBL_MIN</code> – minimum normalized positive value of {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_TRUE_MIN</code>, <code>DBL_TRUE_MIN</code>, <code>LDBL_TRUE_MIN</code> (C11) – minimum positive value of {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_MAX</code>, <code>DBL_MAX</code>, <code>LDBL_MAX</code> – maximum finite value of {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_ROUNDS</code> – rounding mode for floating-point operations
| |
| *<code>FLT_EVAL_METHOD</code> (C99) – evaluation method of expressions involving different floating-point types
| |
| *<code>FLT_RADIX</code> – radix of the exponent in the floating-point types
| |
| *<code>FLT_DIG</code>, <code>DBL_DIG</code>, <code>LDBL_DIG</code> – number of decimal digits that can be represented without losing precision by {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_EPSILON</code>, <code>DBL_EPSILON</code>, <code>LDBL_EPSILON</code> – [[Machine epsilon|difference between 1.0 and the next representable value]] of {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_MANT_DIG</code>, <code>DBL_MANT_DIG</code>, <code>LDBL_MANT_DIG</code> – number of <code>FLT_RADIX</code>-base digits in the floating-point significand for types {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_MIN_EXP</code>, <code>DBL_MIN_EXP</code>, <code>LDBL_MIN_EXP</code> – minimum negative integer such that <code>FLT_RADIX</code> raised to a power one less than that number is a normalized {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_MIN_10_EXP</code>, <code>DBL_MIN_10_EXP</code>, <code>LDBL_MIN_10_EXP</code> – minimum negative integer such that 10 raised to a power one less than that number is a normalized {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_MAX_EXP</code>, <code>DBL_MAX_EXP</code>, <code>LDBL_MAX_EXP</code> – maximum positive integer such that <code>FLT_RADIX</code> raised to a power one more than that number is a normalized {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>FLT_MAX_10_EXP</code>, <code>DBL_MAX_10_EXP</code>, <code>LDBL_MAX_10_EXP</code> – maximum positive integer such that 10 raised to a power one more than that number is a normalized {{cpp|float}}, {{cpp|double}}, {{cpp|long double}} respectively
| |
| *<code>DECIMAL_DIG</code> (C99) – minimum number of decimal digits such that any number of the widest supported floating-point type can be represented in decimal with a precision of <code>DECIMAL_DIG</code> digits and read back in the original floating-point type without changing its value. <code>DECIMAL_DIG</code> is at least 10.
| |
| | |
| =={{anchor|stdint.h|inttypes.h}}Fixed-width integer types==
| |
| | |
| The [[C99]] standard includes definitions of several new integer types to enhance the portability of programs.<ref name="c99"/> The already available basic integer types were deemed insufficient, because their actual sizes are implementation defined and may vary across different systems. The new types are especially useful in [[Embedded system|embedded environments]] where hardware supports usually only several types and that support varies from system to system. All new types are defined in <code><inttypes.h></code> header (<code>cinttypes</code> header in C++) and also are available at <code><stdint.h></code> header (<code>cstdint</code> header in C++). The types can be grouped into the following categories:
| |
| | |
| * Exact-width integer types which are guaranteed to have the same number '''N''' of bits across all implementations. Included only if it is available in the implementation.
| |
| * Least-width integer types which are guaranteed to be the smallest type available 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 which are guaranteed to be the fastest integer type available in the implementation, that has at least specified number '''N''' of bits. Guaranteed to be specified for at least N=8,16,32,64.
| |
| * Pointer integer types which are guaranteed to be able to hold a pointer
| |
| * Maximum-width integer types which are guaranteed to be the largest integer type in the implementation
| |
| | |
| The following table summarizes the types and the interface to acquire the implementation details ('''N''' refers to the number of bits):
| |
| | |
| {| class=wikitable
| |
| |-
| |
| ! rowspan=2 | Type category
| |
| ! colspan=3 | Signed types
| |
| ! colspan=3 | Unsigned types
| |
| |-
| |
| ! Type
| |
| ! Minimum value
| |
| ! Maximum value
| |
| ! Type
| |
| ! Minimum value
| |
| ! Maximum value
| |
| |-
| |
| ! Exact width
| |
| | <code>int'''N'''_t</code> || <code>INT'''N'''_MIN</code> || <code>INT'''N'''_MAX</code>
| |
| | <code>uint'''N'''_t</code> || 0 || <code>UINT'''N'''_MAX</code>
| |
| |-
| |
| ! Least width
| |
| | <code>int_least'''N'''_t</code> || <code>INT_LEAST'''N'''_MIN</code> || <code>INT_LEAST'''N'''_MAX</code>
| |
| | <code>uint_least'''N'''_t</code> || 0 || <code>UINT_LEAST'''N'''_MAX</code>
| |
| |-
| |
| ! Fastest
| |
| | <code>int_fast'''N'''_t</code> || <code>INT_FAST'''N'''_MIN</code> || <code>INT_FAST'''N'''_MAX</code>
| |
| | <code>uint_fast'''N'''_t</code> || 0 || <code>UINT_FAST'''N'''_MAX</code>
| |
| |-
| |
| ! Pointer
| |
| | <code>intptr_t</code> || <code>INTPTR_MIN</code> || <code>INTPTR_MAX</code>
| |
| | <code>uintptr_t</code> || 0 || <code>UINTPTR_MAX</code>
| |
| |-
| |
| ! Maximum width
| |
| | <code>intmax_t</code> || <code>INTMAX_MIN</code> || <code>INTMAX_MAX</code>
| |
| | <code>uintmax_t</code> || 0 || <code>UINTMAX_MAX</code>
| |
| |}
| |
| <!--
| |
| Macros which will convert constant decimal, octal or hexadecimal value which will suit the corresponding type are also defined:
| |
| * <code>INTMAX_C(''value'')</code> is substituted for a value suitable for <code>intmax_t</code>.
| |
| * <code>UINTMAX_C(''value'')</code> is substituted for a value suitable for <code>uintmax_t</code>.<ref name=pubs />
| |
| | |
| ==Other integer limits==
| |
| * <code>PTRDIFF_MIN</code> is the minimum value of <code>[[Stddef.h#Type ptrdiff_t|ptrdiff_t]]</code>.
| |
| * <code>PTRDIFF_MAX</code> is the maximum value of <code>ptrdiff_t</code>.
| |
| * <code>SIZE_MAX</code> is the maximum value (2<sup>16</sup> − 1 or greater) of <code>[[Stddef.h#Type size_t|size_t]]</code>.
| |
| * <code>WCHAR_MIN</code> is the minimum value of <code>[[Stddef.h#Type wchar_t|wchar_t]]</code>.
| |
| * <code>WCHAR_MAX</code> is the maximum value of <code>wchar_t</code>.
| |
| * <code>WINT_MIN</code> is the minimum value of <code>wint_t</code>.
| |
| * <code>WINT_MAX</code> is the maximum value of <code>wint_t</code>.
| |
| * <code>SIG_ATOMIC_MIN</code> is the minimum value of <code>sig_atomic_t</code>.
| |
| * <code>SIG_ATOMIC_MAX</code> is the maximum value of <code>sig_atomic_t</code>.
| |
| -->
| |
| | |
| ===Printf and scanf format specifiers===
| |
| | |
| The <code><inttypes.h></code> header (<code>cinttypes</code> header in C++) provides features that enhance the functionality of the types defined in <code><stdint.h></code> header. Included are macros that define [[printf format string]] and [[scanf format string]] specifiers corresponding to the <code><stdint.h></code> types and several functions for working with <code>intmax_t</code> and <code>uintmax_t</code> types. This header was added in [[C99]].
| |
| | |
| ;Printf format string
| |
| | |
| The macros are in the format <code>PRI''{fmt}{type}''</code>. Here ''{fmt}'' defines the output formatting and is one of <code>d</code> (decimal), <code>x</code> (hexadecimal), <code>o</code> (octal), <code>u</code> (unsigned) and <code>i</code> (integer). ''{type}'' defines the type of the argument and is one of <code>'''N'''</code>, <code>FAST'''N'''</code>, <code>LEAST'''N'''</code>, <code>PTR</code>, <code>MAX</code>, where <code>'''N'''</code> corresponds to the number of bits in the argument.
| |
| ;Scanf format string
| |
| | |
| The macros are in the format <code>SCN''{fmt}{type}''</code>. Here ''{fmt}'' defines the output formatting and is one of <code>d</code> (decimal), <code>x</code> (hexadecimal), <code>o</code> (octal), <code>u</code> (unsigned) and <code>i</code> (integer). ''{type}'' defines the type of the argument and is one of <code>'''N'''</code>, <code>FAST'''N'''</code>, <code>LEAST'''N'''</code>, <code>PTR</code>, <code>MAX</code>, where <code>'''N'''</code> corresponds to the number of bits in the argument.
| |
| | |
| ;Functions
| |
| | |
| {{expand section|date=October 2011}}
| |
| | |
| ==Additional floating-point types==
| |
| | |
| The [[C99]] standard includes new floating-point types <code>float_t</code> and <code>double_t</code>, defined in <code><math.h></code>. They correspond to the types used for the intermediate results of floating-point expressions when <code>FLT_EVAL_METHOD</code> is 0, 1, or 2. These types may be wider than <code>long double</code>.
| |
| <!-- This is quite short for a section. Perhaps this could be moved to the "Basic types" one though these are not basic types (just like the new C99 integer types). -->
| |
| | |
| ==Structures==
| |
| | |
| Structures are a way of storing multiple pieces of data in one variable. For example, say we wanted to store the name and birthday of a person in strings, in one variable. We could use a structure to house that data:
| |
| | |
| <source lang="c">
| |
| struct birthday
| |
| {
| |
| char name[20];
| |
| int day;
| |
| int month;
| |
| int year;
| |
| };
| |
| </source>
| |
| | |
| Structures may contain pointers to structs of its own type, which is common in [[linked data structure]]s.
| |
| | |
| A C implementation has freedom to design the memory layout of the struct, with few restrictions; one being that the memory address of the first member will be the same as the address of struct itself. Structs may be [[C syntax#Initialization|initialized]] or assigned to using compound literals.
| |
| | |
| A user-written function can directly return a structure, though it will often not be very efficient at run-time.
| |
| | |
| ==Arrays==
| |
| For every type ''T'', except void and function types, there exist the types “array of ''N'' elements of type ''T''”.
| |
| | |
| An array 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-1''.
| |
| | |
| There are also "arrays of unspecified size" where the number of elements is not known by the compiler.
| |
| | |
| For example:
| |
| <source lang="c">
| |
| int cat[10]; // array of 10 elements, each of type int
| |
| int bob[]; // array of an unspecified number of 'int' elements.
| |
| </source>
| |
| | |
| Arrays can be initialized with a compound initializer, but not assigned. Arrays are passed to functions by passing a pointer to the first element.
| |
| | |
| Multidimensional arrays are defined as "array of array …". All but the outermost dimension must have compile-time constant size:
| |
| | |
| <source lang="c">
| |
| int a[10][8]; // array of 10 elements, each of type 'array of 8 int elements'
| |
| float f[][32]; // array of unspecified number of 'array of 32 float elements'
| |
| </source>
| |
| | |
| ==Pointer types==
| |
| For every type ''T'' there exists a type “pointer to ''T''”.
| |
| | |
| Variables can be declared as being [[pointer (computer programming)|pointers]] to values of various types, by means of the <code>*</code> type declarator. To declare a variable as a pointer, precede its name with an asterisk.
| |
| <source lang="c">
| |
| char *square;
| |
| long *circle;
| |
| </source>
| |
| | |
| Hence "for every type T" also applies to pointer types there exists multi-indirect pointers like <code>char**</code> or <code>int***</code> and so on. There exists also "pointer to array" types, but they are less common than "array of pointer", and their syntax is quite confusing:
| |
| | |
| <source lang="c">
| |
| char *pc[10]; // array of 10 elements of 'pointer to char'
| |
| char (*pa)[10]; // pointer to a 10-element array of char
| |
| </source>
| |
| | |
| <code>pc</code> consumes 10×<code>sizeof(char*)</code> bytes (usually 40 or 80 bytes on common platforms), but <code>pa</code> is only one pointer, so <code>sizeof(pa)</code> is usually 4 or 8, and the data it refers to is an array of 10 bytes: <code>sizeof(*pa) == 10</code>.
| |
| | |
| ==Unions==
| |
| Union types are special structures which allow access to the same memory using different type descriptions; one could, for example, describe a union of data types which would allow reading the same data as an integer, a float or a user declared type:
| |
| <source lang="c">
| |
| union
| |
| {
| |
| int i;
| |
| float f;
| |
| struct
| |
| {
| |
| unsigned int u;
| |
| double d;
| |
| } s;
| |
| } u;
| |
| </source>
| |
| In the above example the total size of <code>u</code> is the size of <code>u.s</code> (which happens to be the sum of the sizes of <code>u.s.u</code> and <code>u.s.d</code>), since s is larger than both <code>i</code> and <code>f</code>. When assigning something to <code>u.i</code>, some parts of <code>u.f</code> may be preserved if <code>u.i</code> is smaller than <code>u.f</code>.
| |
| | |
| Reading from a union member is not the same as casting since the value of the member is not converted, but merely read.
| |
| | |
| ==Function pointers==
| |
| Function pointers allow referencing functions with a particular signature. For example, to store the address of the standard function <code>abs</code> in the variable <code>my_int_f</code>:
| |
| | |
| <source lang="c">
| |
| int (*my_int_f)(int) = &abs;
| |
| // the & operator can be omitted, but makes clear that the "address of" abs is used here
| |
| </source>
| |
| | |
| Function pointers are invoked by name just like normal function calls. Function pointers are separate from pointers and [[void pointer]]s.
| |
| | |
| ==See also==
| |
| {{wikibooks|C Programming|Variables|C Programming}}
| |
| * [[C syntax]]
| |
| * [[Uninitialized variable]]
| |
| | |
| ==References==
| |
| {{Reflist}}
| |
| | |
| {{CProLang}}
| |
| | |
| {{use dmy dates|date=January 2012}}
| |
| | |
| {{DEFAULTSORT:C Variable Types And Declarations}}
| |
| [[Category:C programming language]]
| |
| [[Category:C standard library]]
| |