Programming in C Chapter-1 Overview of C By:Vani Kapoor Nijhawan Assistant Professor, VIPS Ms. Vani Kapoor Nijhawan, VIPS 1 Importance of Subject • C is a Structured, machine independent and High Level language developed by Dennis Ritchie at AT & T’s Bell Laboratories of USA in 1972. • To be a Good Programmer one must know fundamentals of C programming language. Ms. Vani Kapoor Nijhawan, VIPS 2 Importance of C Language Parts of many operating systems like Windows, UNIX, Linux is written in C because nothing beats C in the speed of execution. Moreover, if one is to extend the operating system to work with new devices one needs to write device driver programs, which are exclusively written in C. Mobile phones and palmtops and devices like microwave oven, washing machines and digital cameras are getting smarter by the day. This smartness comes from a microprocessor, an operating system and a program embedded in this devices. These programs have to run fast but also have to work in limited amount of memory. With these constraints, C is the language of choice while building such operating systems and programs. In several 3D computer games where the user navigates some object, like say a spaceship and fires bullets the game has to react fast to the user inputs. This is where C language scores over other languages. Many popular gaming frameworks have been built using 3 C language. Ms. Vani Kapoor Nijhawan, VIPS History of ‘C’ ❑ Root of the modern language is ALGOL 1960. It’s first computer language to use a block structure. It gave concept of structured programming. ❑ In 1967, Martin Richards developed a language, BCPL (Basic Combined Programming Language) Ms. Vani Kapoor Nijhawan, VIPS 4 History of ‘C’ ❑ In 1970,by Ken Thompson created a language called as ‘B’. ❑ In 1972,by Dennis Ritchie introduced new language called as ‘C’ . Ms. Vani Kapoor Nijhawan, VIPS 5 History of ‘C’ 1972 Traditional C 1978 K&R C 1989 1990 1999 Dennis Ritchie Kernighan &Ritchie C89/ANSI C ANSI Committee ANSI/ISO C ISO Committee C99 Standardization Commitee 6 Ms. Vani Kapoor Nijhawan, VIPS Features Of ‘C’ ❖ It is a robust language with the capabilities of assembly language and features of high level language. ❖ It is suitable for writing system softwares and business packages also. ❖ Programs written in ‘C’ are efficient and fast. (Because of variety of data types and powerful operators) ❖ Highly Portable. (related to OS) ❖ Well suited for structured programming.(Blocks) ❖ Ability to extend itself. (Addition to C library) Ms. Vani Kapoor Nijhawan, VIPS 7 Program & Programming Language Program:A program is a well defined set of instructions which when carried out by processor for some specific input, generates a specific output. Programming language:The manner of writing a program with some predefined rules is called a programming language. It includes symbols and rules which are related to their use as a part of language. i.e. Pascal, C, C++, Python, JAVA, .NET 8 Ms. Vani Kapoor Nijhawan, VIPS Types of languages ❖ Lower level languages:- Languages which are in machine executable form i.e. machine language, Assembly language. ❖ Higher level languages:Languages which are programmer understanable than to machine i.e. C++,Visual basic,Java. Ms. Vani Kapoor Nijhawan, VIPS 9 Executing a HLL program ❖ There are two ways to run programs written in any high-level language. ❖ First way is to compile the program. ❖ The other method is to pass the program through an interpreter. Ms. Vani Kapoor Nijhawan, VIPS 10 C Compiler: Functions ❖ ❖ C compiler checks for syntax errors in the code, if any In case if no errors are found, it returns success and converts ‘C source code into object code form – which is nearer to machine executable code. Ms. Vani Kapoor Nijhawan, VIPS 11 Linker: Role A linker is a program that combines object modules to form an executable program. Ms. Vani Kapoor Nijhawan, VIPS 12 C Program: Example /* Program to print a message*/ // Message.C #include<stdio.h> /* link section*/ void main() /* execution of program*/ { printf(“Welcome to the World of C ”); } Ms. Vani Kapoor Nijhawan, VIPS 13