Types and Declarations

Variables must be defined in C before they are used. The declaration of a variable in C establishes the type of the object and its storage class.


Types

type possible size (bits) corresponding values
char 8 0 to 255
short
short int
16 -32768 to 32767
int 32 -2147483648 to 2147483647
long
long int
32 -2147483648 to 2147483647
float 32 real numbers to about 6 s.f.
double 64 real numbers to about 15 s.f.
long double 128 real numbers to about 33 s.f.

Possible implementation sizes

Integer


Floating Point


Character
may also be signed or unsigned (default is implementation-dependent);


Void
By default functions return a value of type int; to specify that no value is returned use void.


Constants
e.g, const float pi = 3.141



Example


Storage Classes

Storage class defines scope and lifetime of a variable.

Extern
Such variables are global; lifetime is the duration of the programme. Variables declared outside of any function have storage class extern.


Auto
Variables declared within a function have storage class auto --- they have scope local to the function; their lifetime is that of the invocation (call) of the function.


Static
The value of such a variable is preserved between successive calls to a function (scope: local).


Register
Used in programme optimisation...



...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_course_crash_in_c/_reml_grp/index.reml
On: 3/3/2003 at 17:43:41
Options: reml2 -i noindex -l long -o html -p multiple