Variable data types in C


 

C supports the following variable data types:

Here's an example using integers, doubles floating-points and character data types <datatypes1.c>

We'll deal with pointers, structures, and other user-defined data-types later; these are more advanced data-types. In this section, let's focus primarily on integers, doubles/floating-points, and characters.


Type int
Integers are numbers with no decimal points, for example 123, 0, -321 are valid integers.


Type double/float
Variables that contain a decimal point. Floating-points can also be expressed in scientific notation, for example, 2.4e-7, is a valid double/float.
Doubles and floating-point numbers(floats) are similar; doubles can store almost twice as many significant digits as floats.
Example <double_float.c> illustrates this


Type char
A single character. Must be enclosed in single quotes when assigned to a variable.


Important Note
All variables in C must be declared at the beginning of the program. Variables can be assigned a value at the same time that it being declared, for example,
int MyInt = 0;
Also, you can declare multiple variables at the same line, as long as they have the same type, for example,
int MyInt = 0, YourInt = 1;