Flylib.com

Books Software

 
 
 

Miscellaneous Operators

I l @ ve RuBoard

Miscellaneous Operators

sizeof yields the size, in units the size of a char value, of the operand to its right. Typically, a char value is one byte in size. The operand can be a type- specifier in parentheses, as in sizeof (float) , or it can be the name of a particular variable, array, or so on, as in sizeof foo . A sizeof expression is of type size_t .

(type) is the cast operator and converts the following value to the type specified by the enclosed keyword(s). For example, (float) 9 converts the integer 9 to the floating-point number 9.0 .

, is the comma operator; it links two expressions into one and guarantees that the left most expression is evaluated first. The value of the whole expression is the value of the right-hand expression. This operator is typically used to include more information in a for loop control expression.

Example

for (step = 2, fargo = 0; fargo < 1000; step *= 2)
        fargo += step;
I l @ ve RuBoard
I l @ ve RuBoard

Appendix C. BASIC TYPES AND STORAGE CLASSES

Summary: The Basic Data Types

Summary: How to Declare a Simple Variable

Summary: Qualifiers

I l @ ve RuBoard
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