Now that you know how to print (output) data on screen, you might think how to make your program reads (input) values from the keyboard? But first before performing input operation, we need a 'container' (variables) that can be used to store data (i.e input value).
A variable is a storage (memory location) where you can read and write data when necessary. A variable must be declared before it is used. Declaring a variable is performed by specifying its type and name. Consider the following program.
#include<stdio.h>
int main()
{
int V;
V = 15;
printf("The value of V is %d\n", V);
return 0;
}The first statement declare a variable
V = 15;
The value of 15 is assigned to variable
printf("The value of V is %d\n", V);The
The
Now what is the value to be printed by
Data Types
In the previous section we have discussed the first basic data type which is integer. As has been mentioned, integer is a sequence of one or more digits such as 15 and -382. Besides integer, C provides floating point and character data types.
Integer
Integers can be expressed in base other than decimal (base 10). If 0 is preceding the integer value, the integer is considered to be in octal notation (base 8). For example, to express 17 in octal which is equivalent to 15 in decimal, the notation is 017. An octal value can be printed by specifying its conversion specification,
printf("The value of V is %o\n", V);
printf("The value of V is %x\n", V);Output
The value of V is f
Floating point
Floating point is a number with decimal point (radix point) such as 3.1417, 0.158 and -2.718. Floating point number also can be expressed in exponential notation. For example, 299,792,458 can be represented as 2.997925e8 which is equivalent to 2.997925 x 108. To print floating point number, conversion specification
Character
A character in C includes letters, numerics, punctuations and control characters. Punctuations are symbols that indicates the structure and organization of written language such as colon (:), comma (,) and apostrophe ('). Control characters do not correspond to any particular symbol in natural language. Examples of control characters are carriage return, tab and backspace. Variables that are declared as character can store a single character. A character constant is formed by enclosing the character with a pair of single quotation marks such as
lttr = 'Z';
printf("lttr is %c\n", lttr);