1Variables

What is a Variable?

Variables allow us to assign specified values or take values from the program and process them. We actually wouldn't be able to program anything without variables.

/* Example variables: */

int = Stores integers, whole numbers: 1, 5, 10, 1337
float = Stores decimal values: 10.1, 13.9, 1.3498 
char = Stores string or text.

Example values:
int age = 15;
float grade = 13.37;
char name = "William"; /* #Text or Strings have to be in quotes. */

Notes:

  • Variables can be named anything (it's up to your personal preference, however name them something that you will understand what they do!)

  • Variables can store any value (Integer, Strings, Float etc)


Format Specifiers

Format specifiers are crucial in C programming, they are used to tell the compiler what type of data variable is storing and should be expecting.

Format specifiers can be easily spotted when you see "%" in code.

Note:

  • Using the wrong format specifier will cause errors and program will not work

Last updated