Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Variables are used to store the value during the execution of a program. The name itself means, the
value of variable can be changed hence the name “Variable“. The variables are stored in Main Memory
i.e. RAM (size depending on the data type). In C Programming we always have to declare variable before
we can use them. Note that the space is allocated to variable in memory during execution or run-time.
C is a strongly typed language. What this means it that, the type of a variable cannot be changed.
Suppose we declared an integer type variable so we cannot store character or a decimal number
in that variable.
There are set of rules to be followed while declaring variables and data types in C Programming:
• The 1st letter should be alphabet.
The char data type is usually one byte, it is so called because they are commonly used to store single
characters. The size of the other types is dependent on machine. Most desktop machines are “32-bit”,
this refers to the size of data that they are designed for processing. On “32-bit” machines the int data type
takes up 4 bytes (232). The short is usually smaller, the long can be larger or the same size as
an int and finally the long long is for handling very large numbers.
The type of variable you use generally doesn’t have a big impact on the speed or memory usage of your
application. Unless you have a special need you can just use int variables. We will try to point out the few
different cases like. A decade ago, most machines had 16-bit processors, this limited the size
of intvariables to 2 bytes. At the time, short variables were usually also 2 bytes and long would be 4
bytes. Nowadays, with 32-bit machines, the default type (int) is usually large enough to satisfy what used
to require a variable of type long. The long long type was introduced more recently to handle very large
numeric values.
EXAMPLE 3: Calculate Size of Data type on Your Machine
To find out the size of each data type on your machine compile and run this program. It uses one new
language construct sizeof(). This tells us how many bytes a data type takes up.
[crayon-5b86eba1cbadd597692340/] The output from this program would be: