Chapter 345

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Chapter 3

Overview of C
History and C as middle level language.
C as procedure-oriented programming
Structure of a C program
Application Areas
C Program development life cycle
History of C Language
 Developed in 1972 by Dennis Ritchie at Bell Laboratories
of AT&T, U.S.A.
 Designed for implementation UNIX operating system
 Programming languages developed before C language:

Language Year Developed By


Algol 1960 International Group
BCPL 1967 Martin Richards
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
Feature of C
 Simple
 It provides a structured approach (to break the problem into parts), the rich set
of library functions, data types, etc.
 Machine Independent or Portable
 Unlike assembly language, c programs can be executed on different
machines with some machine specific changes. Therefore, C is a machine
independent language.
 Mid-level programming language
 C is intended to do low-level programming. It is used to develop system
applications such as kernel, driver, etc. It also supports the features of a high-
level language. That is why it is known as mid-level language.
 Structured programming language
 we can break the program into parts using functions. So, it is easy to understand
and modify. Functions also provide code reusability. It follows the top-down approach
 Memory Management
 supports the feature of dynamic memory allocation. In C language, we can free
the allocated memory at any time by calling the free() function.
Structure of C Program
Documentation Section

Link Section
Definition Section

Global Declaration Section


Function Section
main()
{
Declaration Part
Executable Part
}
Subprogram Section
Function 1
Function 2 User
. defined
. functions
Function n
Consists of comment lines to convey some
program information.
Comments are enclosed in /* */
Eg: /* My First C Program */

Declares the header files to be used in the


Documentation Section program. Helps the Compiler to link the
specified header file or library files to the
Link Section program
Eg: #include <stdio.h>
Definition Section

Global Declaration Section Define the symbolic constants required in


the program
Eg: #define PI = 3.142
Global variables and functions are declared
in this section
Every C program must have one main()
Function Section function.
main() It has variable declaration and
{ executable C statements enclosed in
Declaration Part curly { } brackets
Eg: int main()
Executable Part
{
} int a;
Subprogram Section printf(“Hello World”);
Function 1 }
Function 2
. Contains all user-defined functions
.
Function n
Sample C Program

/* Program to add two integer numbers */ Documentation


#include<stdio.h> Link Section
int main( ) main function
{
int a = 5, b = 3, ans; variable declaration
ans = a + b; executable
printf(“ Sum = %d”, ans); statements
}
Functions as building blocks

 Function is block of statements that perform a specific task.


 Every C program has atleast one function called main()
 Program execution starts from main and ends when all
instructions in main are executed.
 C has many library functions/pre-defined functions
 Programmers can also write their own functions called user-
defined functions

 C is also known as Procedure-oriented programming


language.
C Program Development Lifecycle

Standard
libraries

Pre-processed code
Edited C Source Object Executable
Editor Compiler Linker
Program code code code

Creation Compilation Linking


Start

Type the program


Source Program
Compiler
program.c
Edit the program Compile the source code

Yes If syntax
error? Object Program
program.obj
No
No
Linker
Link Program
Executable Program
program.exe or
Execute Program a.out

No If output
correct?

Yes
Stop
Applications of C

 Operating Systems
 GUI
 Embedded Systems
 Database
 Gaming
 Text Editors
 Drivers
References:

1. Programming in ANSI C, E Balagurusamy

2. www.javatpoint.com

You might also like