History of C Language:

C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A. 

Dennis Ritchie is known as the founder of the c language. Initially, C language was developed to be used in UNIX operating system. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and clean style, these features make C language suitable for system programming like an operating system or compiler development. Many later languages have borrowed syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript, and many other languages are mainly based on C language. C++ is nearly a superset of C language .

·

Features of C Language: 

C is the widely used language. It provides many features that are given below.

1. Simple

2. Machine Independent or Portable

3. Mid-level programming language

4. structured programming language

5. Rich Library

6. Memory Management

7. Fast Speed

8. Pointers

9. Recursion

10. Extensible



Basic Structure of C Program: 



First C Program :

#include<stdio.h> 

int main()

{

 printf("Hello C Language");

return 0;

 }

 Save the file with name first.c

 Output: Hello C Language 

 

Different sections of the above code:

Documentation Section :

This section consists of comment lines which include the name of programmer, the author and other details like time and date of writing the program.  Documentation section helps anyone to get an overview of the program.

Example :

/* file: circle.c

author: yusuf shakeel

date: 2010-11-25

description: program to find the area of a circle using the radius r */

●This section contains a multi line comment describing the code.

● In C, we can create single line comment using two forward slash // and we can create multi line comment using /* */.

● Comments are ignored by the compiler and is used to write notes and document code.

 

Link Section :

● The 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. Example #include <stdio.h>,#include<math.h>

● This section includes header file.

● We are including the stdio.h input/output header file from the C library. Definition Section-- All the symbolic constants are written in definition section. #define PI=3.14

● This section contains constant.

● In the above code we have created a constant PI and assigned 3.1416 to it.

● The #define is a preprocessor compiler directive which is used to create constants. We generally use uppercase letters to create constants.

● The #define is not a statement and must not end with a ; semicolon.

 

Global Declaration Section :  

● The global variables that can be used anywhere in the program are declared in global declaration section.

● This section also declares the user defined functions. float area(float r);

● This section contains function declaration.

● We have declared an area function which takes a floating number (i.e., number with decimal parts) as argument and returns floating number.

Main Function Section :

  • It is necessary have one main() function section in every C program.
  • This section contains two parts, declaration and executable part.
  • The declaration part declares all the variables that are used in executable part.
  • These two parts must be written in between the opening and closing braces.
  • Each statement in the declaration and executable part must end with a semicolon (;).
  • The execution of program starts at opening braces and ends at closing braces. Example-- 

void main(void) 

{

 float r = 10; 

area=3.14*r*r; 

printf("Area: %.2f", area(r));

 }

● This is the main() function of the code.

● Inside this function we have created a floating variable r and assigned 10 to it.

● Then we have called the printf() function.

The first argument contains "Area: %.2f" which means we will print floating number having only 2 decimal place. In the second argument we are calling the area() function and passing the value of r to it.

 

Sub Program Section :

  • The subprogram section contains all the user defined functions that are used to perform a specific task.
  • These user defined functions are called in the main() function.
  • This section contains a subprogram, an area() function that is called from the main() function.
  • This is the definition of the area() function. It receives the value of radius in variable r and then returns the area of the circle using the following formula           PI * r * r.

Header files :

● C language has numerous libraries that include predefined functions to make programming easier.

● In C language, header files contain the set of predefined standard library functions.

● Your request to use a header file in your program by including it with the C preprocessing directive “#include”.

● All the header file have a ‘.h’ an extension.

● By including a header file, we can use its contents in our program.

Syntax: #include or #include "filename.h"

● It offers the above features by importing them into the program with the help of a preprocessor directive “#include”.

● These preprocessor directives are used for instructing compiler that these files need to be processed before compilation.

● In C program should necessarily contain the header file which stands for standard input and output used to take input with the help of scanf() and printf() function respectively.

Standard Header Files And Their Uses:

#include<stdio.h>: It is used to perform input and output operations using functions scanf() and printf().

#include<iostream.h>: It is used as a stream of Input and Output using cin and cout.

#include<string.h>: It is used to perform various functionalities related to string manupulation like strlen(), strcmp(), strcpy(), size(), etc.

#include<math.h>: It is used to perform mathematical operations like sqrt(), log2(), pow(), etc.