Before a program is written, the variable required in a program is to be declared with considering the value they may contain.
A declaration consists of a data types, followed by variable name, ending with a semicolon.
Initial value can be assigned to variable at the same time when they are declared with in a type declaration.
Ex:- int j=123;
A variable can be assigned some value after its creation.
Ex:- int a;
General Structure of C- Program
A C program should be written as.
Input & Output
Data can be entered in the program by mean of some functions which are already defined in the standard C library.
scanf function :
Data entered by input device is taken by C-library function scanf. The usually used input statement is scanf () function.
- General syntax of the scanf :
- Writing Output
scanf (control string, arg1, arg2, -----, argn);
where control string refers to a string containing required formatting information & arg1, arg2,---- argn are variable that represent the individual input data values.
|C||Data item is character|
|D||Data item is integer|
|E||Floating point value|
|F||Floating point value|
Ex. scanf (“%d”, &age);
The format string must be a text enclosed in double quotes. It contains the information for interpreting the entire data for connecting it into internal representation in memory.
The usually used output statement is printf (). It is one of the library functions.
Syntax: printf (“format string”, argument list);
Format string may be a collection of escape sequence or/and conversion specification or/and string constant. The format string directs the printf function to display the entire text enclosed within the double quotes without any change.