Professional Documents
Culture Documents
C Program in Computer
C Program in Computer
Comments in C
If you construct a long program today and try to recall it after a few days, there is every
possibility that you would have forgotten quite a few things and even what the program
does or what a particular name stands for. Comments if included in a program help in
recollection of different names, data values and other parameters.
Escape Sequences in C
Escape sequences are basically control characters used for formatting the output.
These are combinations of a backslash and a character in lowercase. We have already
used "\n", which shifts the curser to the next line. Table lists the escape sequences
defined in C language.
Features of C
Anatomy of C Program
We have some compiler preprocessor commands. This includes various
#include files. Then comes the main function. Some name can also be given
to the main function. Then, we have the variable declarations used in the
main code. Then we have sub-functions.
There are many "languages" like, for example C, Fortran, PASCAL etc., that help us to
convert an algorithm in to something that a computer can understand. We will focus
here only on C programming So. let us start looking at how do we create a "C program".
What is Libraries file in C
Another component common to C programs is the header file. This
supplies information about the standard library functions. These files all end with the .h
extension and are added to the program using the #include pre-processor directive. All
C compilers use a pre-processor as their first phase of compilation to manipulate the
code of the source file before it is compiled.
Pre-Processor Directive in C
Macros are small functions (generally single line functions) which may be dealt with the help of
preprocessor directive #define. Here, we shall discuss only the directive #define which is also used to
define constants. A macro may or may not have parameters. An advantage of using a macro is that if a
program involves a large number of the function calls of a small function the overburden of function calls
can make the program inefficient; in case of macro, the code is substituted wherever the macro occurs.
Thus, a programmer does not have to repeat the code again and again in the source code of the program
while the function call is eliminated. However, a disadvantage of using macro is that data types are not
included in the macro nor are these checked by the compiler. A few illustrations of macros are given
below.
Precision for Characters and Strings in C
The field width and precision setting may be used for characters and strings as well. However, these have
different meaning. See the following code:
Precision Setting in C
Precision is specified by the number of digits after the decimal point for the outputs for float as well as
double numbers. If precision is not specified, it would be according to the default setting in
the computer which is generally 6 digits. The precision may be specified by a period(.) followed by a
positive number equal to the number of digits desired. An illustration is given below.
Type Casting in C
Type casting or type conversion refers to change of type of variables or pointers or user-defined objects
from one type to another type. The need for type conversion arises in some operations involving two
operands of different types, or even of same type. The example given below illustrates this concept.