Variables and Data Types
In programming, variable is a symbolic name given for some piece of information. The purpose of such assignment is to allow the name to be used independently of the information it represents. A variable has three attributes - name, value and the address, where it is stored. Each variable is classified by its type. There is a great variety of data types that can be used in programming. Such classifications determines the possible values for a certain data type, the way of storing it, as well as, the operations that are possible to perform. C language contains the following data types:
int integer type, represents natural integer type. It is a signed type, so it can contain positive and negative numbers, unless it is declared as the unsigned int, then only positive values are allowed. The int type is at least 16-bits wide. There is also a long int, which is between 16 and 32-bits wide and a short int, which is at least 16-bits, but is no longer than int. C99 addition provides a long long int type, which is at least 64-bits, but no shorter than a long type.
Example of declaration:
int x=5;
char A single character can be defined as a character type of data. Characters are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be applied to char type.
Example of declaration:
char c = ‘9’;
float - single-precision floating point value. It is 32-bits wide.
double - double-precision floating point value. It is 64-bits wide.
string - string type is a sequence of characters terminated with the null sign “\0”. It is usually stored as a one-dimension character array.
const - Each variable may be preceded by the type of const and after assigning it a value, it remains unchanged.
enum - This data type allows grouping logically connected values and assigning them to a certain variable. In other words it is the enumeration type.
Example of declaration:
enum color {red, yellow, magenta, blue, green}
extern - is used for global variables that are shared across code in several files.
static - data type can be applied to global variables, it means, that they are local to a file and inaccessible from the other files.