Summary: The Basic Data Types

I l @ ve RuBoard

Summary: The Basic Data Types

C's basic types fall into two categories: integers and floating-point numbers . The different varieties give you choices for range and precision.

Keywords

The basic data types are set up using the following eight keywords: int , long , short , unsigned , char , float , double , and signed (ANSI C).

Signed Integers

Signed integers can have positive or negative values.

int is the basic integer type for a given system.

long or long int can hold an integer at least as large as the largest int and possibly larger; long is at least 32 bits.

The largest short or short int integer is no larger than the largest int , and may be smaller. A short is at least 16 bits. Typically, long is bigger than short , and int is the same as one of the two. For example, C DOS compilers for the PC provide 16-bit short and int and 32-bit long . It all depends on the system.

The long long type provided by the C9X committee is at least as big as long and is at least 64 bits.

Unsigned Integers

Unsigned integers have zero or positive values only, which extends the range of the largest possible positive number. Use the keyword unsigned before the desired type: unsigned int , unsigned long , unsigned short , or unsigned long long . A lone unsigned is the same as unsigned int .

Characters

Characters are typographic symbols such as A , & , and + . By definition, one byte of memory is used for a char variable. In the past, 8 bits has been the most typical size for char . However, the internationalization of C might lead to 16-bit bytes.

char is the keyword for this type.

Some implementations use a signed char , but others use an unsigned char . ANSI C allows you to use the keywords signed and unsigned to specify which form you want. Technically, char , unsigned char , and signed char are three distinct types, with the char type having the same representation as one of the other two.

Floating Point

Floating-point numbers can have positive or negative values.

float is the basic floating-point type for the system. It can represent at least six significant digits accurately. Typically, float uses 32 bits. double is a (possibly) larger unit for holding floating-point numbers. It may allow more significant figures and perhaps larger exponents than float . It can represent at least ten significant digits accurately. Typically, double uses 64 bits. long double is a (possibly) even larger unit for holding floating-point numbers. It may allow more significant figures and perhaps larger exponents than double .

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net