C Language Introduction
C Language Introduction
C is a procedural programming language initially developed by Dennis Ritchie in the year 1972 at Bell
Laboratories of AT&T Labs. Dennis Ritchie is known as the founder of the c language.
It was developed to overcome the problems of previous languages such as B, BCPL, etc.
It was mainly developed as a system programming language to write the UNIX operating system. It
inherits many features of previous languages such as B and BCPL.
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
1) Simple
C is a simple language in the sense that it provides a structured approach (to break
the problem into parts), the rich set of library functions, data types, etc.
5) Rich Library
C provides a lot of inbuilt functions that make the development fast.
6) 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.
7) Speed
The compilation and execution time of C language is fast since there are lesser inbuilt
functions and hence the lesser overhead.
8) Pointer
C provides the feature of pointers. We can directly interact with the memory by using the
pointers. We can use pointers for memory, structures, functions, array, etc.
9) Recursion
In C, we can call the function within the function. It provides code reusability for
every function. Recursion enables us to use the approach of backtracking.
10) Extensible
C language is extensible because it can easily adopt new features.
Structure of a C program
The structure of a C program means the specific structure to start the programming in the C
language. Without a proper structure, it becomes difficult to analyze the problem and the solution. It
also gives us a reference to write more complex programs.
C language combines the power of a low-level language and a high-level language. The low-level
languages are used for system programming, while the high-level languages are used for application
programming. It is because such languages are flexible and easy to use. Hence, C language is a widely
used computer language.
It supports various operators, constructors, data structures, and loop constructs. The features of C
programming make it possible to use the language for system programming, development of
interpreters, compilers, operating systems, graphics, general utilities, etc. C is also used to write
other applications, such as databases, compilers, word processors, and spreadsheets.
Memory allocation: At the time of definition, memory is assigned to a variable name, allowing
dynamic allocation of the memory. It means that the program itself can request the operating
system to release memory for use at the execution time.
Bit-manipulation: It refers to the manipulation of data in its lowest form. It is also known as bits. The
computer stores the information in binary format (0 and 1).
Sections of a C program
The sections of a C program are listed below:
1. Documentation section
2. Preprocessor section
3. Definition section
4. Global declaration
5. Main function
Documentation section
It includes the statement specified at the beginning of a program, such as a program's name, date,
description, and title. It is represented as:
1. //name of a program
Or
1. /*
3. .
4. */
Both methods work as the document section in a program. It provides an overview of the program.
Anything written inside will be considered a part of the documentation section and will not interfere
with the specified code.
Preprocessor section
The preprocessor section contains all the header files used in a program. It informs the system to
link the header files to the system libraries. It is given by:
1. #include<stdio.h>
2. #include<conio.h>
The #include statement includes the specific file as a part of a function at the time of the
compilation. Thus, the contents of the included file are compiled along with the function being
compiled. The #include<stdio.h> consists of the contents of the standard input output files, which
contains the definition of stdin, stdout, and stderr. Whenever the definitions stdin, stdout, and
stderr are used in a function, the statement #include<stdio.h> need to be used.
There are various header files available for different purposes. For example, # include <math.h>. It is
used for mathematic functions in a program.
Define section
The define section comprises of different constants declared using the define keyword. It is given by:
1. #define a = 2
Global declaration
The global section comprises of all the global declarations in the program. It is given by:
2. int a = 5;
3. char ch ='z';
char = 1 byte
float = 4 bytes
int = 4 bytes
We can also declare user defined functions in the global variable section.
Main function
main() is the first function to be executed by the computer. It is necessary for a code to include the
main(). It is like any other function available in the C library. Parenthesis () are used for passing
parameters (if any) to a function.
1. main()
We can also use int or main with the main (). The void main() specifies that the program will not
return any value. The int main() specifies that the program can return integer type data.
1. int main()
Or
1. void main()
Main function is further categorized into local declarations, statements, and expressions.
Local declarations
The variable that is declared inside a given function or block refers to as local declarations.
1. main()
2. {
3. int i = 2;
4. i++;
5. }
Statements
The statements refers to if, else, while, do, for, etc. used in a program within the main function.
Expressions
An expression is a type of formula where operands are linked with each other by the use of
operators. It is given by:
1. a - b;
2. a +b;
The user defined functions specified the functions specified as per the requirements of the user. For
example, color(), sum(), division(), etc.
The program (basic or advance) follows the same sections as listed above.
Return function is generally the last section of a code. But, it is not necessary to include. It is used
when we want to return a value. The return function returns a value when the return type other
than the void is specified with the function.
Return type ends the execution of the function. It further returns control to the specified calling
function. It is given by:
1. return;
Or
1. return expression ;
For example,
return 0;
Examples
It is given by:
2. #include<stdio.h>
3. int main()
4. {
5. int a, b, sum;
8. // calculating sum
9. sum = a + b;
12. }
13. </stdio.h>
Output
It reads data from the standard input stream and writes the
scanf()
result into the specified arguments.