Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 1: INTORDUCTION TO C LANGUAGE

Similar presentations


Presentation on theme: "CHAPTER 1: INTORDUCTION TO C LANGUAGE"— Presentation transcript:

1 CHAPTER 1: INTORDUCTION TO C LANGUAGE
Programming languages: A programming language is a computer language programmers use to develop applications or other set of instructions for a computer to execute. A programming language is a formal language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.

2 ASSEMBLY LANGUAGE MACHINE LANGUAGE

3

4 CATEGORIES OF PROGRAMMING LANGUAGES
A HIGH LEVEL LANGUAGE is a language for programming computers which does not require detailed knowledge of a specific computer. High-level languages do not have to be written for a particular computer, but must be compiled for the computer they will work with. High-level languages are closer to human language than low-level languages, and include statements like GOTO or FOR which are regular words. On the other hand, a LOW LEVEL LANGUAGE is a computer programming language that is close to machine language. MACHINE LANGUAGE is at the lowest level, because it is the actual binary code of 1s and 0s that the computer understands. ASSEMBLY LANGUAGES are low- level languages which are translated into machine code by an assembler. Each assembly language instruction corresponds to one machine language instruction, but assembly language is easier notation for the programmer to use than machine code.

5

6 High Level Language Assembly Language Machine Language

7 SOURCE CODE OBJECT CODE HIGH LEVEL LANGUAGE PROGRAM MACHINE LANGUAGE PROGRAM COMPILER OR INTERPRETER ASSEMBLY LANGUAGE PROGRAM ASSEMBLER

8 Compiler: It is a program which translates a high level language program into a machine language program. A compiler goes through the entire program and then translates the entire program into machine codes. Interpreter: An interpreter is a program which translates statements of a program into machine code. It translates only one statement of the program at a time. It reads only one statement of program, translates it & executes it. Then it reads the next statement of the program again translates it & executes it. In this way it proceeds further till all the statements are translated and executed. On the other hand, a compiler goes through the entire program and then translates the entire program into machine codes. A compiler is 5 to 25 times faster than an interpreter. Assembler: A computer will not understand any program written in a language, other than its machine language. The programs written in other languages must be translated into the machine language. Such translation is performed with the help of software. A program which translates an assembly language program into a machine language program is called an assembler.

9 High level Languages: Very early in the development of computers attempts were made to make programming easier by reducing the amount of knowledge of the internal workings of the computer that was needed to write programs. If programs could be presented in a language that was more familiar to the person solving the problem, then fewer mistakes would be made.  High-level programming languages allow the specification of a problem solution in terms closer to those used by human beings. These languages were designed to make programming far easier, less error-prone and to remove the programmer from having to know the details of the internal structure of a particular computer. These high-level languages were much closer to human language. Many high level languages have appeared (and many have also disappeared!). 

10 COBOL Business applications FORTRAN Engineering & Scientific Applications PASCAL General use and as a teaching tool C & C++ General Purpose - currently most popular PROLOG Artificial Intelligence JAVA General Purpose - gaining popularity rapidly COBOL COmmon Business-Oriented Language FORTRAN  Formula Translation BASIC Beginner's All-purpose Symbolic Instruction Code

11 Become A Better Programmer Learn C Programming Language

12 A Brief History of C C is a general-purpose language. The C programming language was devised in the early 1970s by Dennis M. Ritchie at Bell Labs, to implement the UNIX operating system. Characteristics of C Language C is an All purpose programming language. It is equally suitable for generating high level application and low level application. Sometimes it is also called the mid-level language. C language encourages the users to write their own library function so that they can extend the features of the language. C program can be executed on any type of computers. The program written in C language can be converted into machine language more efficiently. Computer games can be generated in C language which is accomplished through the usage of sound graphics. C is close to hardware. Both low and high level programming can be done in C language. It is a highly structured language.

13 A C program basically has the following form: Preprocessor Commands
Functions Variables Statements & Expressions Comments Braces and semicolon To print “I Love Pakistan” on screen following simple C program can be used: # include <stdio.h> void main(void) { printf(“I Love Pakistan”); } Preprocessor Commands # sign indicates that this is an instruction for the compiler <stdio.h> stands for standard input-output header printf( ) is a library function used to print. The left brace { indicates the start of the body of the any function. The right brace } indicates the end of the body of the any function. A statement in C is terminated with a semicolon. : Preprocessor Commands: These commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation.

14 A C program can basically has the following form:
Preprocessor Commands Functions Variables Statements & Expressions Comments Braces and semicolon To print “I Love Pakistan” on screen following simple C program can be used: # include <stdio.h> void main(void) { printf(“I Love Pakistan”); }

15 # sign indicates that this is an instruction for the compiler
<stdio.h> stands for standard input-output header printf( ) is a library function used to print. The left brace { indicates the start of the body of the any function. The right brace } indicates the end of the body of the any function. A statement in C is terminated with a semicolon: Preprocessor Commands: These commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation.

16 Note the followings C is a case sensitive programming language. It means in C printf and Printf will have different meanings. C has a free-form line structure. End of each C statement must be marked with a semicolon. Multiple statements can be one the same line. Statements can continue over multiple lines.

17 What is a C Program? A collection of functions which when compiled, assembled, linked, loaded, and executed performs some task.                                        

18 Compile: Translate a program from source code to assembly code.  
Assemble: Translate a program from assembly code to object code (sometimes these two steps are combined and called compiling).   Link: Pull together all of the functions needed for the program (both user defined objects and system libraries) and arrange that locations of functions and variables are known. This step creates the executable program.   Load: Move the executable program into computer memory. Execute: Run the program, that means now the computer is going to act upon the instructions given in the program.

19 C Program Compilation Creating, Editing, Saving, Compiling, Debugging, Linking, Executing Creating C Program Editing C Program Saving C Program You can write, edit and save a C program in any text editor program. But Turbo C provides a complete IDE for this purpose. You can easily write, edit and save C program in TC editor. The process of writing a new C program by following the rules of C language is called creating a C program. To write a new C program, load the TC editor and type the source code of program. You can also make changes during writing new programs as well as in the exiting C program. Therefore, the process of writing, changing and revising the source code is called editing program. After writing or editing the source program, you should save it on the disk as text file with an extension " .c ". This process is called saving the program.

20 The Edit-Compile-Link-Execute Process: Developing a program in a compiled language such as C requires at least four steps: Editing (Or Writing) The Program Compiling It Linking It Executing It Editing: You write a computer program with words and symbols that are understandable to human beings. This is the editing part of the development cycle. You type the program directly into a window on the screen and save the resulting text as a separate file. This is often referred to as the source file . The custom is that the text of a C program is stored in a file with the extension .c for C programming language. Compiling: You cannot directly execute the source file. To run on any computer system, the source file must be translated into binary numbers understandable to the computer's Central Processing Unit. This process produces an intermediate object file - with the extension .obj, the .obj stands for Object.

21 Linking: The first question that comes to most peoples minds is Why is linking necessary? The main reason is that many compiled languages come with library routines which can be added to your program. Theses routines are written by the manufacturer of the compiler to perform a variety of tasks, from input/output to complicated mathematical functions. In the case of C the standard input and output functions are contained in a library (stdio.h) so even the most basic program will require a library function. After linking the file extension is .exe which are executable files. Executable files: Thus the text editor produces .c source files, which go to the compiler, which produces .obj object files, which go to the linker, which produces .exe executable file. You can then run .exe files as you can other applications, simply by typing their names at the DOS prompt or run using windows menu.

22 Structure of C Programs
C's character set C's keywords the general structure of a C program that all C statement must end in a ; that C is a free format language all C programs use header files that contain standard library functions. Before writing any kind of program, one should have the concept of Flowcharts, which is the graphical representation of program.

23

24

25 Example: Write a C program to find the factorial of any number n.

26

27 Write a C program to find the factorial of any number n.
# include <stdio.h> # include <conio.h> void main(void) {   int n, j,fact;   printf(“\nEnter a number: ");   scanf("%d", &n); fact=1;   for(j=1; j<=n; j=j+1)       fact=fact*j;   printf(“\nThe Factorial of %d is %d", n, fact);   return 0; }

28


Download ppt "CHAPTER 1: INTORDUCTION TO C LANGUAGE"

Similar presentations


Ads by Google