<<<...WHAT IS MAIN()...>>>
main () forms a crucial part of any C program.Let us understand its purpose as well as its intricacies.
(a)main() is a function.It is a container for a set of statements. A C program may have multiple functions.
If it contains only one functions.If it contains only one function its name has to be main().All statements
that belong to main() are enclosed within a pair of braces{}.
(b)Like functions in a calculator, functions in C also return a values.main() function always returns
an integer value,hence there is an int before main().It is known as return type if the function.The
integer value that we are returning is 0. 0 indicates seccess.If statement in main() fail to do intended work
we can return a non-zero number from main().This indicate failure.
(c) The way to watch the value returned by main() varies from one compiler to another.
(d) Some compilers like Turbo C/C++ even permit us to return nothing from main().In such a case we should
precede it with the keyword void.But this is the non-standard way of writing the main() function.
<<<...VARIABLES AND THEIR USAGE...>>>
Let us understand the significance of constants and variables with reference to our program.
(A) Any variabe used in the program must be declared before it is used.For example,
int p,n; /*declaration*/
float r,si; /*declaration*/
si= p*n*r/100; /*usage*/
(B)In the statement,
si=p*n*r/100;
* and / are the arithmetic operators.The arithmetic operators available in C are +,-,* and /.
<<<...PRITNTF() AND ITS PURPOSE...>>>
C does not contain any keyword to display output on the screen. All output to screen is achieved using
readymade library functions like printf().Let understand this function with respect to our program.
(a)Once the value to use the printf() to do so.
(b)To be able to use the printf() function, it is Necessary to use #include<stdio.h> at the beginning
of the program.#include is a preprocessor directive.
(c)The general form of printf() function is,
printf("<format string>",<list of variable>);
<format string>can contain,
%f for printing real values
%d for printing integer values
%c for pritnting character values
In addition to format specifiers like %f, %d and %c, in the format string may also contaiprintf()n any other characters.
These characters are printed as they are when printf() is executed.
(d)Given below are some more examples of usage of printf() function:
printf("%f",si)
printf("%d %d %f %f",p,n,r,si);
printf("simple interest=Rs.%f",si);
printf("principle=%d\nRate=%f",p,r);
The output of the last statement would look like this...
Principle =1000
Rate=8.500000
The output is split over tw lines because of newline character '\n'.It sends the cursor to next line.
It is one of the several Escape Sequences available in C.
(e) printf() can pritnt values of variables as well as result of an expressions like 3, 3+2,c and a+b*c-d
as shown below.
printf("%d%d%d",3,3+2,c,a+b*c-d);
NOTE THAT 3 AND C ALSO REPRESENT VALID EXPRESSIONS.
AND SO ON......
''.....IN THE NEXT BLOG WE WILL DISCUSS ABOUT SOME IMPORTANT QUESTION AND SOLUTION(BASIC PROGRAM).....''
Must read this-TYPES OF C CONSTANTS,RULES FOR CONSTRUCTING INTEGER CONSTANTS,TYPES OF C VARIABLES
YOU CAN ALSO READ THIS POST...>>>MY FIRST C PROGRAM,C KEYWORDS
TYPES OF C CONSTANTS,RULES FOR CONSTRUCTING INTEGER CONSTANTS,TYPES OF C VARIABLES
0 Comments