DATA TYPES AND CONSTANTS
The four basic data types are
The keyword used to define integers is,
int
An example of an integer value is 32. An example of declaring an integer variable called sum is,
int sum; sum = 20;
float
An example of a float value is 34.12. An example of declaring a float variable called money is,
float money; money = 0.12;
double
An example of a double value is 3.0E2. An example of declaring a double variable called big is,
double big; big = 312E+7;
char
An example of a character value is the letter A. An example of declaring a character variable called letter is,
char letter; letter = 'A';
Note the assignment of the character A to the variable letter is done by enclosing the value in single quotes. Remember the golden rule: Single character - Use single quotes.
Sample program illustrating each data type
#include < stdio.h > main() { int sum; float money; char letter; double pi; sum = 10; /* assign integer value */ money = 2.21; /* assign float value */ letter = 'A'; /* assign character value */ pi = 2.01E6; /* assign a double value */ printf("value of sum = %d\n", sum ); printf("value of money = %f\n", money ); printf("value of letter = %c\n", letter ); printf("value of pi = %e\n", pi ); } Sample program output value of sum = 10 value of money = 2.210000 value of letter = A value of pi = 2.010000e+06