c programming language was developed in the seventies by a group of at the bell telephone lab

14
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. Introduction to C Introduction to C Lecture #9 Lecture #9

Upload: torie

Post on 06-Jan-2016

24 views

Category:

Documents


0 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

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

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.

Introduction to CIntroduction to C

Lecture #9Lecture #9

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

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

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

Components of a C Program: A C program has, the following three basic components:

i) Header File

ii) Main Function

iii) Sub Functions

i. 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 Structure of a C Programming

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

ii. 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.

Structure of a C Programming Structure of a C Programming

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

iii. 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.

}

Structure of a C Programming Structure of a C Programming

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

#include<stdio.h>

#include<conio.h>

main()

{

clrscr();

printf(“My first C program”);

text();

}

text()

{

printf(“Welcome”)

}

A Sample C ProgramA Sample C Program

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

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.

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

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.

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

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

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

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(“------”);

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

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.

i. Single line comment

ii. 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 */

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

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.

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

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.

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

Object

Code

Expended

Library

Executable

PreprocessorC source

code

Header file

Expended Code

First Phase

Compiler Object

Code

Second Phase

Linkage editor

Third Phase