Header files or Library files, The main( ) function, Pre-processor directive, Expression, Address and size of operator
To view other topics related to Computer. Click Here.
Header files or Library files
Header file are part of C compiler. These files contain definitions of standard library functions. There are several header files. Each header file contains definitions of one type of function only.
For example, the math.h header file contains definitions of mathematical functions available in C language. Each header file has an execution .h. The preprocessor directive “include” is used to add a header file into the program. The name of the file is written in angle brackets (< >) after “#include” directive. The syntax to include a header file is:
#include
Given the name of the header file in angle rackets specifies that the header file is located in the include directory of the compiler program.
The main( ) function:-
The main( ) function indicates the beginning of a C program. This function must be included in every C program. When a C program executed, the control goes to main ( ) function. It is the entry point of all C programs.
The statements within this function are the main body of the C program. If main ( ) function is not included, the program is not compiled and an error massage is generated.
The syntax of the main ( ) function is:
Void main (void)
{
Program statements……
}
The main ( ) function may take one or more values. Similarly, it may also output one value.
Pre-processor directive: -
The instructions that are given to the compiler before the beginning of the actual program are called preprocessor directives. These arte also called compiler directives. These are written at the beginning of the source program. These preprocessor directives start with a number sign (#) and the key word “include” or “define”.
These are the instructions or directives that tell the compiler to take the actions before compiling the source program. The program that handles the preprocessor directives is called the preprocessor because it does some processing before the compilation process actually starts.
There are two types of pre-processor in C language.
The # include directive: -
The # include is a pre-processor directive. It is used to include or import a source text into source program. It is usually used to import header files into a program.
The syntax to use the # include directive is:
# include
Giving the name of the header file in angle brackets specifies that the file is located in the include directory of the compiler program.
The name of the file to be imported can also be written in double quotes. When the name of the file is written in double quotes, it specifies that the file is to be loaded from the directory which contains the source program file.
The syntax to include a header file is:
# include “name of the header file”
The # define directive: -
The # define is a pre-processor directive. It is used to assign a constant quantity to an identifier. This directive can be used any where in the program. Its syntax is:
# define identifier constant
Where
Identifier specifies the identifier name to which the constant value is to be assigned.
Constant specifies the constant value that is to be assigned to the identifier.
The identifier specified in the define directive is not a variable. It does not have any data type. The pre-processor simply replaces all occurrences of the identifier with its value in the program statements that follow the directive.
Rules to identify the variable
The rules for identification of variables in the programming are
1. The first character of a variable must be alphabetic one.
2. The maximum length of a variable in turbo C version is up to 31 characters.
3. There should no blank space in between two characters of a variable like AR EA (invalid variable).
4. There should no special character in the variable name, instead of standard core line like spe-d.
5. The variable must be meaningful it may be the first character of that thing or full name like area or a.
6. Reserved C word cannot be used as variable name.
Expression: -
An expression is used for calculating the value of a formula. It is formed by combining different operands and operator. Its evaluation gives a single value. The operands may be constant values, different variable names and functions. Parenthesis may also be used in an expression.
For example, to calculate the value of box with sides A, B, C the expression is written as:
A **B **C
Where A, B, C are variable names and are called operands. The multiplication sign ‘**’ is called operator. The combination of operands and operators makes an expression.
Size of operator:-
The size of operator is used to know the size of a data type being used.
The general form of the size of operator is:
Sizeof (expression)
There expression is the data type or variable, whose size is measured by the size of operator.
Address of operator: -
In C language the ampersand operator i.e. & is called addresses of operator. It is used proceeding with the variable name. It would seem more reasonable to use the name of the variable enough with out the ampersand as we did in printf ( ) statement. However the C language compiler requires the arguments to scanf ( ) to be the addresses of variables, rather then the variables themselves.
In other words we can say every variable name occupies a certain location in the memory and the first character (byte) it occupies is the address of that variable. There fore C language compiler provides ampersand to be places as a prefix with the variable name to over come this problem.
x
Post a Comment