| Variables In order for Computer Processor to read what we type on the keyboard and display it on the computer screen, the processor need a memory called variables to store the character that we type and display it on the computer screen. For example: int p; This line of C code means, "I want to create a space called p that is able to hold a variable of type integer." A variable has a name (in this case, p) and a type (in this case, int, an integer). You can store a value in p by writing the ‘=’ operator (called assignment operator): p = 5; This mean p holding a value 5 in it now. To make use of the value inside variable p, we can type something like: printf("%d", p); This mean value 5 will be displayed on the computer screen. In C, there are several standard types for variables: • int - integer (whole number) values e.g 1,10,40,30 • float - floating point values e.g 1.1,3.33,2.65 • char - single character values (such as "k" or "Q") float p; p=3.123 printf("%f", p); char p; p=k printf("%c", p); Next Page >> |