The C language programming. Introduction theory.

INTRODUCTION


Datei:The C Programming Language logo.svg – Wikipedia

                    C seems a strange name for a programming language. But this strange sounding language is one of the most popular computer languages today. C was an offspring of the 'Basic Combined Programming Language' (BCPL) called B, developed in the 1960's at Cambridge University. B language was modified by Dennis Ritchie and was implemented at Bell Laboratories in 1972. 
                            The new language was named C. Since it was developed along with the UNIX operating system. it is strongly associated with UNIX. This operating system, which was also developed at Bell Laboratories, was coded almost entirely in C.


SAMPLE C PROGRAMS

                    Before discussing any specific features of C, we shall look at some sample C programs and analyse and understand how they work.
Sample Program : Printing a Message Consider a very simple program, This program when executed will produce the following output

Output
I see I remember
Code 
main()
{
//printing begins 
printf( "I see. I remember") 
//printing ends
}
                    Here in the program main is special function used by C language to tell the computer from where the program get starts. ' { } ' are the special operators used in forming the syntax. // is used for comments in c which is visible in code not on execution. printf is predefined, standard C function for printing out the values.

BASIC STRUCTURE OF C PROGRAMS

                    The examples discussed so far illustrate that a C program can be viewed as a group of building blocks called functions. A function is a subroutine that may include one or more statements designed to perform a specific task. To write a C program, we first create functions and then put them together.

1 Documentation Section
2 Link Section
3 Definition Section
4 Global Declaration Section
5 main() Function Section
        declaration Part
        executable Part
6 Subprogram section
        function 1
        function 2
        .              .
        .              .
        Function n

Programming style

                    Unlike some other programming languages (COBOL, FORTRAN etc). C is a free form language. That is, the C compiler does not care, where on the line we begin typing While this be a license for bad programming, we should try to use this fact to our advantage in developing readable programs. Although several alternative styles are possible, we should select one style and use it with total consistency. First of all, we must develop the habit of writing programs in lowercase letters. C program statements are written in lowercase letters. Uppercase letters are used only for symbolic constants. 
                    Braces group program statements together and mark the beginning and the end of functions
is a free form language.A proper indentation of braces and statements would make a program caries to read and debug Note how the braces are aligned and the statements are indented in the program 

Since Math in program is written as

a=b;
x=y+1;
z=a+x;
we can group statements together on one line The
a=b;x=y+1;z=a+x;

EXECUTING A 'C' PROGRAM

                    Executing a program written in C involves a series of steps. These are:
1. Creating the program
2. Compiling the program.
3. Linking the program with functions that are needed from the C library
4. Executing the program

Creating the program

                    Once we load the UNIX Operating system into the memory, the computer is ready to receive the program. The program must be entered into a file. The file name can consist of letters. digits and special characters, followed by a dot and a letter c. 
                    Examples of valid file names are: hello.c programa.c ebg1.c

Compiling the program 

                    Once after creating the program in the UNIX Operating System, the computer finds your program and have prechecking before running the program. and this is known as compiling program. meanwhile if there is an error the system will invoke you with same

Linking the program

                    As such the C language have lots of build in libraries which helps user in  easy programming. As instance we have to to square of something or square root of something we used math lib. and for calling lib we have to use #include(math.h). we have lib like conio stdio math and many more 

Executing the program 

                    Here we do need already perfect working saved program in our system. to activate you need to open up in console and run the program if there is no error that it while work as you wanted if there is the program will exist instants after errors step or will get into infinite loop or will give some garbage value.

Summary

                    1.Every C program requires a main() function (Use of more than one main() is illegal.).The place main is where the program execution begins.
                    2. The execution of a function begins at the opening brace of the function and ends at the corresponding closing brace.
                    3. C programs are written in lowercase letters. However, uppercase letters are used for symbolic names and output strings.
                    4. All the words in a program line must be separated from each other by at least one space.or a tab, or a punctuation mark.
                    5. Every program statement in a C program must end with a semicolon
                    6. All variables must be declared for their types before they are used in the program.
                    7. We must make sure to include header files using #include directive when the program refers to special names and functions that it does not define.
                    8. Compiler directives such as define and include are special instructions to the compiler to help it compile a program. They do not end with a semicolon.
                    9. The sign # of compiler directives must appear in the first column of the line.
                    10. When braces are used to group statements, make sure that the opening brace has a corresponding closing brace.
                    11. C is a free-form language and therefore a proper form of indentation of various sections would improve legibility of the program.
                    12. A comment can be inserted almost anywhere a space can appear. Use of appropriate comments in proper places increases readability and understand ability of the program and helps users in debugging and testing. Remember to match the symbols /" and/ appropriately.


~ Aaditya Rasala

Comments

Post a Comment

Popular Posts