Thursday, February 5, 2009

Introduction to Programming :: Declaring Data Types

The syntax to declare a new variable is first write the desired data type and then the variable name.

Variable Names

-char
-short int
-int
-long int
-bool
-float
-double
-long double

The syntax to declare a new variable is first write the desired data type and then the variable name.
ex: int a;
float number;
string LastName
In cases of multiple variables of the same type its possible to declare them in one statement.
ex: int a, b, c;



Another aspect of declaring variables needs to be taken into account. The variables char, short, long and int can be either signed or unsigned, depending on the values that need to be represented.


Global variables can be referred from anywhere in the code, even inside functions, whenever it is after its declaration.

The scope of local variables is limited to the block enclosed in braces ({}) where they are declared

No comments:

Post a Comment