STRUCTURE OF C :-
#include <headerfile1.h>#include <headerfile2.h>...#include <headerFILE.h>global declarationsreturn-type main(parameter list){statement sequence}return-type function1(parameter list)
{
statement sequence
}
return-type function2(parameter list)
{
statement sequence
}
.
.
.
return-type funcTION(parameter list)
{
statement sequence
}
NOTE: Statements in 'C' are terminated with a SEMI-COLON (;)
Structural Analysis :-
1. #include <headerFILE.h>
Header Files are pre-processor directives that are already present in a folder named "include" that comes with C compiler. They all carry the extension .h and contain functions that have already been provided to the programmer to perform some specific task. For eg.
(a) stdio.h is a header file that contains the Standard Input/Output functions that are needed for basic input/output operations in the program.
(b) conio.h is a header file that deals with the Console Input/Output operations,i.e. dealing with the display on the Console (monitor) when the program is run.
(c) math.h is a header file that provides functions which help in mathematical operations.
2. global declarations
Global declarations are the values that can be used in the complete program or package created. These values and attributes declared globally can be accessed by all the functionc and modules created inside the program.
3. return-type main(parameter list)
'return-type' is the type of value returned by the function.
'main' is special. Our program begins executing at the beginning of main. This means that every program must have a main somewhere. main will usually call other functions to help perform its job, some that you wrote, and others from libraries that are provided for us. 'parameter list' - One method of communicating data between functions is for the calling function to provide a list of values, called arguments, to the function it calls. The parentheses after the function name surround the argument list. In this example, main is defined to be a function that expects no arguments, which can be indicated by the empty list ( ).
NOTE- A C program, whatever its size, consists of functions and variables. A function contains statements that specify the computing operations to be done, and variables store values used during the computation.
The statements of a function are enclosed in braces { }.
Some of the commonly used functions in 'C' are-
1. printf()
This is a function which is used to get the output as a display on the monitor. The arguments passed to this funtion is displayed as an output. It is a library function which is stored in the header file 'stdio.h'.
2. scanf()
This is a function which is used to get the input from the user. The arguments passed to this funtion are taken as an input. It is a library function which is stored in the header file 'stdio.h'.
3. getch()
Generally to hold the output screen on the monitor Alt+F5 is used. Or an alternate way is to use getch() function which is used for the same purpose. It is a library function and is stored in the header file 'conio.h'.
Another function getche() can also be used for the same purpose. The main difference between the two is that the key pressed to return back from the output screen is displayed along with the main output display in the case of getche().
4. clrscr()
This is a library function that is used to clear the output screen and is defined in the header file 'conio.h'.
Note- The character strings are usually placed inside the double quotes ("..."). The sequence \n in the string is C notation for the newline character, which when printed advances the output to the left margin on the next line. Notice that \n represents only a single character. An escape sequence like \n provides a general and extensible mechanism for representing hard-to-type or invisible characters. Among the others that C provides are \t for tab, \b for backspace, \" for the double quote and \\ for the backslash itself.
Also note that any characters between /* and */ are ignored by the compiler; they may be used freely to make a program easier to understand.
DATA TYPES are the types of data that tells the types of values that the variable can store, the type of data that can be dealt with and the associated functions of handling it.
Flow of Control-
1. Sequential control- It is the default flow of control in the program of 'C'.
2. Conditional control- It is the flow of control that depends upon a condition test. For eg. if-else, switch-case.
SYNTAX:
(a) if-else
if (condition)
{...
...}
else
{...
...}
(b) switch-case
switch(testing condition)
{case 1: ...
... break;
case 2: ...
... break;
case ..
..
..
default: ...
}
Note: The conditional or looping statements can be nested also. For further details, kindly Contact us and let us know your queries.
We'll surely respond as soon as possible.
3. Iterative control- It is the flow of control that repeats itself depending upon a condition test. For eg. for, while, do-while..
SYNTAX:
(a) for(initialising statement; condition test; update statement)
{ ...
... statements to be executed repeatedly...(body of loop)
..
}
(b) while(condition test)
{..
...
body of loop...
..}
(c) initialising statement
do
{...
...
..body of loop...
..}
while(condition test);
Till now we are well acquainted with the Basics of 'C' program..
WE WELCOME YOUR SUGGESTIONS AN QUERIES OVER OUR PRECISE DESCRIPTION..
Let us now begin with the basic programming to understand the syntax of various statements that we have learnt so far.So subscribe our Blog to kick off your day with our free stuff.
0 comments:
Post a Comment