C_Introduction
C_Introduction
Introduction
➢ C programming is a general-purpose, procedural, imperative computer programming
language.
➢ Developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories
• To develop the UNIX operating system
• For creating system applications that directly interact with the hardware devices such
as drivers, kernels, etc.
➢ C programming is considered as the base for other programming languages, that is why it is
known as mother language.
➢ It is also known as
• Mother language - most of the compilers, JVMs, Kernels, etc. are written in C
language, and most of the programming languages follow C syntax, for example, C++,
Java, C#, etc.
• Mid-level programming language - It supports the feature of both low-level and high-
level languages. C language program is converted into assembly code, it supports
pointer arithmetic (low-level), but it is machine independent (a feature of high-level).
➢ Advantages of C Language
• Efficiency and speed
• Portable
• Close to Hardware
• Standard Libraries
• Structured Programming
• Procedural Language
• Versatility
➢ Drawbacks of C Language
• Manual Memory Management
• No Object−Oriented Feature
• No Garbage Collection
• No Exception Handling
➢ Applications of C Language
• System Programming
• Embedded Systems
• Compiler and Interpreters
• Database Systems
• Networking Software
• Game Development
• Text Editor and IDEs
• Scientific and Mathematical Applications
➢ Example
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
Course Code: CSE-121 Course Title: Structured Programming Language
Example:
#include <stdio.h>
#define PI 3.14159
int main() {
float radius = 5.0;
float area = PI * radius * radius;
➢ Compilation process in C
• The compilation is a process of converting the source code into object code. It is
done with the help of the compiler.
• The compiler checks the source code for the syntactical or structural errors, and if
the source code is error-free, then it generates the object code.
• The c compilation process converts the source code taken as input into the object
code or machine code. The compilation process can be divided into four steps, i.e.,
Pre-processing, Compiling, Assembling, and Linking.
• The preprocessor takes the source code as an input, and it removes all the
comments from the source code. The preprocessor takes the preprocessor
directive and interprets it. For example, if <stdio.h>, the directive is available in
the program, then the preprocessor interprets the directive and replace this
directive with the content of the 'stdio.h' file.
Course Code: CSE-121 Course Title: Structured Programming Language
Preprocessor
The source code is the code which is written in a text editor and the source code file is given an
extension ".c". This source code is first passed to the preprocessor, and then the preprocessor
expands this code. After expanding the code, the expanded code is passed to the compiler.
Compiler
The code which is expanded by the preprocessor is passed to the compiler. The compiler converts
this code into assembly code. Or we can say that the C compiler converts the pre-processed code
into assembly code.
Assembler
The assembly code is converted into object code by using an assembler. The name of the object
file generated by the assembler is the same as the source file. The extension of the object file in
DOS is '.obj,' and in UNIX, the extension is 'o'. If the name of the source file is 'hello.c', then the
name of the object file would be 'hello.obj'.
Linker
Mainly, all the programs written in C use library functions. These library functions are pre-
compiled, and the object code of these library files is stored with '.lib' (or '.a') extension. The
main working of the linker is to combine the object code of library files with the object code of
our program.
Course Code: CSE-121 Course Title: Structured Programming Language
➢ Comments in C
• Using comments in a C program increases the readability of the code.
• In C, there are two types of comments –
i. Single-line comments
ii. Multi-line comments
• Syntax of Single-line C comment: //comment text
• Multi-line Comment in C:
/* The comment starts here
Line 1
Line 2
…..
…..
Comment ends here*/