C programming language was developed in the seventies by a group of at the Bell Telephone lab. - PowerPoint PPT Presentation

slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
C programming language was developed in the seventies by a group of at the Bell Telephone lab. PowerPoint Presentation
Download Presentation
C programming language was developed in the seventies by a group of at the Bell Telephone lab.

play fullscreen
1 / 14
C programming language was developed in the seventies by a group of at the Bell Telephone lab.
Download Presentation
Download Presentation

C programming language was developed in the seventies by a group of at the Bell Telephone lab.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Introduction to C Lecture #9 • C programming language was developed in the seventies by a group of at the Bell Telephone lab. • The C language was the outline of two earlier languages known as BCPL and B-Language. • there two languages are specially used to write code for an operating system. • Dennis Ritchie is credited with the first working description of C • In 1978, Brain Reslnighan, & Ritchie published a manuscript which is referred to as K8R version of C. • In 1983, the ANSI convened a technical committee to standardize C. • Today, most commercial C compiler generally comply with the ANSI standard.

  2. C was originally developed to write the Unix Operating System. It was designed to be a special purpose language for system programming. • These days, C is exclusively used for building OS, utilities, application packages, & customized software. • Several can temporary OS, not ably OS/2, windows and XENIX are largely coded in C. • Likewise, many general purpose packages for word processing, spreadsheet, database management one written in C. • Because of its power and efficiency, C has gained immenure popularity. It is increasing used by system programmers, application developers and researchers for a variety of programming tasks

  3. Components of a C Program:A C program has, the following three basic components: • Header File • Main Function • Sub Functions • Header File • The header files contains basic definitions and other related information used by the compiler. • The header files came as a an integral part of the C compiler system. • The relevant file is added to a C program by the compiler directive #include • it has following form #include<fname> • Where fname refers to header file name, the header file have extension “.h” Structure of a C Programming

  4. Structure of a C Programming • Main Function • The second components of C program is always the main function. It has the following structure. main() { data types specifies; statements; } • The definition of main begins with the keyword main. • The entries/statements in this function are enclosed in pair of braces. {} • The main function may certain input/output statement assignment statements, control structures & function calls.

  5. Structure of a C Programming • Sub Function • The third component of a C program may be a sub function. It is an optional module when called from the main function, it performs some specialized or repetitive task, and returns control to the calling function after compiling the work in C program. • The function can be define as: function name function name { Statement 1 statements that will executed Statement 2 when function is called. }

  6. A Sample C Program #include<stdio.h> #include<conio.h> main() { clrscr(); printf(“My first C program”); text(); } text() { printf(“Welcome”) }

  7. Code Explanation: (about source code) • The first entry in #include<stdio.h> it tells the compiler to add the contents of the header file <stdio.h> to the program. • In the main function, the first entry specifies is the printf( ) statement, which display some text on screen. • The statement (text); is a function call. This function simply display another text statement on screen. • The operation of main function is terminated on reaching the closing brace. The control is the passed to the OS. • Next to the main function in the code for the function text( ). It has identified by the function name text. In function text ( ) the printf statement display text that it contain. • Like the main function the entries in the function are also enclosed in a pair the braces.

  8. Coding and Punctuation Rules : A C program is created using a word processor or text editor. The text editor generally forms a part of an integrated C compiler system. The program created by the editor is known as “Source Code” Extension of C program:A C program is identified by name with extension .C In C program statements may not be can fixed to any fixed rows or columns. However the punctuation symbols like spaces, semicolon & commas have special significance. White Spaces: In C, blank (space character), horizontal tabs, carriage returns are referred to has white space. C compiler ignores all white spaces that appear either before or after a statement.

  9. Example: main() { printf(“C Program”); } May also written an a single line main () { printf(“C Program”); } similarly, the header files may also written as #include<stdio.h> #include<conio.h> However, the header entry & file name should be on the same line. Exp: #include <stdio.h> Invalid entry

  10. Semicolons:In a C program, all specifications for the program variables, statements and functions calls must end with a semicolon (;) Commas: In C, commas are used to separate entries in a variable list. Upper Case and Lower Case: The C compilers are generally case sensitive. This means that a distinction is made b/w the upper case & lower case alphabets. In C all keywords are spelt in lower case. Example: The following statements are illegal b/c keywords contain capital letters. #Include<Stdio.h> Main () Invalid statement {---} PrintF(“------”);

  11. Adding Comments to a C program: comments are normally used for documentation or clarification of complex processing steps. Comments can be places at any point in a C programs. In C, there are two types of comments. • Single line comment • Multiple line comment i. Single line comment:single line comments entry begins with the special character // (Slash) ii. Multiple line comment: multiple line comment entry begins with character combination /* (Slash asterik ) and with the combination */. The compiler ignores all comments entries, including the comment symbol. Exp: //sample Program /* A sample program written by me */

  12. Processing a C Program • A program written in C is called source program. The C compiler converts the source code in to set of machine instruction. The translated code is often referred to as executable code. • The translation of source code takes place in 3 stages. • In the first phase, a special component of C compiler known a C preprocessor is used. It adds the contents of header files to user programs. • The output of the preprocessor in then fed to the C compiler. The compiler generates a series of machines instruction for each statement in the source code.

  13. The output of compiler is called an object code. • In the 3rd phase, the object code is processed by a special program called linkage editor. • Linkage editor combines code for library functions & inserts it into the program object code. The out put of the linkage editor is the executable code.

  14. C source code Expended Code Preprocessor Header file First Phase Expended Compiler Object Code Second Phase Object Code Linkage editor Executable Library Third Phase