Variables

Friday, September 03, 2004

 

Variables

Variable

A variable is used to hold data within your program. A variable represents a location in your computer's memory. You can put data into this location and retrieve data out of it. Every variable has two parts, a name and a data type.

Variable Names
Valid names can consist of letters, numbers and the underscore, but may not start with a number.
A variable name may not be a C keyword such as if, for, else, or while. Variable names are case sensitive. So, Age, AGE, aGE and AgE could be names for different variables, although this is not recommended since it would probably cause confusion and errors in your programs.

Variable Types

int
Is used to declare an integer variable. Note that integer variables truncate the remainder on division while floating point variables do not. On 32-bit machines, ints are typically stored in 32-bits and are equivalent to longs. On 64-bit machines, ints may be stored in 32 or 64 bits. Thus, they may be equivalent to either short or long. Check your system documentation.
float
Float variables are used to hold non-integer, floating point values.
double
Double variables are used to store floating-point values. They offer greater precision and can store larger numbers than floats.
char
keyword used to declare a character variable. Character variables are typically stored in one byte.
bool
Bool variables are used for boolean, true/false values.

Variable Declaration
A declaration is used to specify the name and type of an object to the compiler. It asserts that the object exists, but does not actually allocate space for it or create it.

Examples:

int myFunction(float arg1, int arg2 ); // Declaration of a function

extern float radius; //Declaration of a variable or object

class Cat; //Declaration of a class in C++





<< Home

Archives

September 2004  

This page is powered by Blogger. Isn't yours?