Introduction to C
  • Introduction
  • History of C
  • Advantages and Disadvantages of C programming
  • Structure of C Program
  • Sample C Program

Historical Development of C

  • C programming language was developed in 1972 by Dennis Ritchie at bell laboratories (Formerly AT&T Bell Laboratories - American Telephone & Telegraph), located in the U.S.A.
  • It was developed to overcome the problems of previous languages such as B (1970), BCPL (1967), etc. Therefore it inherits many features of previous languages such as B and BCPL.
  • Initially, C language was developed to be used in UNIX operating system.

Features of C Language

Simple: C code resemble with English language which is simple to understand.
Machine Independent or Portable: C programs can be executed on different machines.
Structured programming language: C is a structured programming language in the sense that we can break the program into parts using functions and it also provide code reusability.
Rich Library: C provides a lot of inbuilt functions that make the development fast.
Memory Management: It supports the feature of dynamic memory allocation. In C language, we can free the allocated memory at any time by calling the free() function.
Fast Speed: The compilation and execution time of C language is fast.
Pointers: We can directly interact with the memory by using the pointers.
Recursion: In C, we can call the function within the function. It provides code reusability for every function.
Extensible: C language is extensible because it can easily adopt new features.

C in Present Context

  • According to Toptal, UNIX operating systems are written in C and most of Linux is also in C.
  • For decades, the world’s most used operating system i.e. Windows OS, with about 90 percent of the market share, has been powered by a kernel written in C.
  • Every program and driver in a Mac, as in Windows and Linux computers, is running on a C-powered kernel.
  • iOS, Android and Windows Phone kernels are also written in C. They are just mobile adaptations of existing Mac OS, Linux and Windows kernels. So smartphones you use every day are running on a C kernel.
  • Also databases such as Oracle Database, MySQL, MS SQL Server, and PostgresSQL are coded in C.
  • Other programming languages, like C++, C#, JAVA are derived from the language C and the compilers or interpreters of Python and Perl, are also written in C.

Structure of C Program

1. Documentation section /* Program name: Addition of two numbers given by user. */
Author: Jen
Date: May 30, 2021
Time: 11:00 A.M.
2. Link section #include < stdio.h >
#include < conio.h >
#include < math.h >
3. Definition section #define PI 3.1415
4. Global declaraction section void message(); // Function prototype decleration
int a,b = 10;
5. Main function section void main()
{
int a, b, c; //declaration part
clrscr();
printf(“Enter the value for a,b”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“Required sum is %d”,c);
message(); //calling function
getch();
}
6. Subprogram section void message() //called function
{
printf(“This is user define function”);
}
1. Documentation section
Documentation section consists of comment lines which include the name of the program, name of the programmer and other details like time and date of writing the program. Documentation section helps anyone to get an overview of the program. Comments should be enclosed in /* */ and can be written anywhere in the program.

2. Link section
Link section consists of the header files of the functions that are used in the program.
It provides instructions to the compiler to link functions from the system library using the #include directive. A large number of already define general purpose functions are stored in system library.

3. Definition section
This section defines all symbolic constants using the #define directive. Macros are known as symbolic constants.

4. Global declaration section
There are some variables that are used in more than one function. Such variable are called global variables and declared in the global declaration section that is outside of all the functions.
This section also declares all the user-defined functions.

5. Main function section
Every C program must have a main function to start the execution of the program. Body of main function consists of declaration and executable parts enclosed by the opening bracket {and the closing bracket}.
a. Declaration part: The declaration part declares all the variables used in the executable part. b. Executable part: There must be at least one statement in the executable part. All statements in the declaration and executable part end with a semicolon. The closing bracket of the main function is the logical end of the program.

6. Subprogram section
The subprogram section contains all the user-defined functions that are called from the main function. These functions are generally placed immediately after the main function, although they may appear in any order.

Note: All section, except the link section and main () function section may be absent when they are not required.

Assignment Set
  1. Draw a diagram that shows the structure of a C program and briefly discuss each part.
  2. Explain structure of C program with an appropriate example. [4] [2071]
Web hosting by Somee.com