From WikiChip
Difference between revisions of "c/data types"
< c

(initial page ported)
(No difference)

Revision as of 18:57, 13 December 2013

The meaning of a value stored in an object is determined solely by the type of the expression used to access it - for example the type used in the variable declaration. There are two categories of types:

  • object types - types used to describe objects
  • function types - types used to describe functions

Additionally an object may have a complete or incomplete type. An incomplete type is a type that describes an object but lacks information needed to determine its size. For example: an array of unknown size or struct or union types whose members were not specified. A complete type is a type that describes an object with sufficient information needed to determine its size.

Basic Types

Basic types are the fundamental building blocks of all C programs. All basic types are complete types. Basic types are divided into four sub-categories: char type, signed integer types, unsigned integer types, and floating types.

Character Types

There are three distinct character types: char, signed char, and unsigned char. Depending on the implementation used, a char might be signed or unsigned.

Type Explanation Min Macro At least Min Value Max Macro At least Max Value
char Either a "signed char" or a "unsigned char". CHAR_MIN CHAR_MAX
signed char Same as char, guaranteed to be signed. SCHAR_MIN -127 SCHAR_MAX +127
unsigned char Same as char, guaranteed to be unsigned. 0 UCHAR_MAX +255

Signed Integer Types

The standard defines five signed integer types:

  • signed char
  • short int
  • int
  • long int
  • long long intC99

In this list, each type provides at least as much storage as those preceding it.

Type Explanation Min Macro At least Min Value Max Macro At least Max Value since
short
short int
signed short
signed short int
Short signed integer type.
At least 16 bits in size.
SHRT_MIN -32767 SHRT_MAX +32767 C89
int
signed int
An integer type.
At least 16 bits in size.
INT_MIN -32767 INT_MAX +32767
long
long int
signed long
signed long int
A long integer type.
At least 32 bits in size.
LONG_MIN -2147483647 LONG_MAX +2147483647
long long
long long int
signed long long
signed long long int
A long long integer type.
At least 64 bits in size.
LLONG_MIN -9223372036854775807 LLONG_MAX +9223372036854775807 C99

The macros in the table can be found in the <limits.h> header.

C programming language