Variables


Functions in C consist of manipulating variables. These are items of data which we give a name to.

Every variable in C has an explicit type. These types are declared by ourselves or built into the language. We can declare a new variable by writing the name of its type, followed by its name, and optionally setting it to some value using =. This declaration is a statement, and we terminate all statements in C with a semicolon ;.

To create a new int called count we could write the following…

  1. int count;

Or to declare it and set the value…

  1. int count = 10;

Here are some descriptions and examples of some of the built in types.

voidEmpty Type
charSingle Character/Bytechar last_initial = ‘H’;
intIntegerint age = 23;
longInteger that can hold larger valueslong age_of_universe = 13798000000;
floatDecimal Numberfloat liters_per_pint = 0.568f;
doubleDecimal Number with more precisiondouble speed_of_swallow = 0.01072896;