You are on page 1of 23

Outline

 Introduction to C Programming Language


 History of C
 Why the Term C?
 Features of C
 Why to Learn C?
 Applications of C
 First C Program
 Compilation Process
 Variable
2
S
Introduction
C is a procedural programming language.

C is the mother language of all programming language.

 It is a popular computer programming language.

 There are mainly two types of programming languages:


High Level: Which machine cannot understand.
Low Level: Which machine can understand.
However, C is a mid level programming language. 3
S
Introduction (Cont…)
 C is a structured programming language.

 C supports functions that enable easy maintainability of code by


breaking large file into smaller modules.

 Comments in C provides easy readability.

 Programmers need not to worry about the machine that the


program will be using.

 It was developed to be used in UNIX Operating System (OS).


4
S
History
Table 1: History of C

Language Year Developer


ALGOL 1960 International Group
BCPL (Basic Combined 1967 Martin Richards
Programming Language)
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K&R C 1978 Kernighan & Dennis Ritchie
ANSI (American National 1989 ANSI Committee
Standards Institute) C
ANSI/ISO C 1990 ISO Committee
C99 1999 Standardization Committee
5
S
Why the Term C?
 Itinherits many features of previous languages, such as B
and BCPL.

 BCPL is the previous version of 'B' language.

 As many features came from B, it was named as 'C'.

6
S
Features of C
 Procedural Language: Instructions are executed step by step.
 Portable: We can move a C program from one platform to
another, and run it without any or minimal changes.
 Speed: It is faster than most programming languages like Java,
Python, etc.
 General Purpose: C programming can be used to develop
operating systems, databases, embedded systems, and many more.
 Structured Language: It has the ability to divide and hide all the
information and instruction. Code can be partitioned into C using
functions or code block.
 Limited number of Keywords.
7
S
Why to Learn C?
C helps us to understand the internal architecture of a
computer, how computer stores, and retrieves information.
 It is easy to learn other programming languages like Java,
Python, etc., if we learn C.
 Opportunity to work on open source projects is increased, if
we go through C.
 Some of the largest open source projects, such as Linux
kernel, Python interpreter, SQLite database, etc., are written
in C programming.

8
S
Applications of C
 Embedded system
 Operating system
 Graphical User Interface (GUI) (Ex: Adobe’s Photoshop)
 Browsers and their extensions (Ex: Google's Chromium)
 Databases (Ex: MySQL)
 Compiler production
 Internet of Things (IoT) applications
 Gaming (Ex: Tic-Tac-Toe)

9
S
First C Program
#include<stdio.h> //Header file
#include<conio.h> //Header file
void main() //Main function
{
printf(“Hello!!! How are you?”); //Statement
}

10
S
First C Program (Cont…)
 Header File
The files, which are specified in the include section is called as
Header File.
include is a directory, where all the header files like stdio.h, conio.h,
etc. are kept.
Angular brackets < and > instruct the preprocessor to look in the
standard folder, where all header files are kept.
Header file is given in .h extension.
These are precompiled files that have some predefined functions.
conio.h stands for “Console Input Output”, which manages
input/output on console based application.
stdio.h stands for Standard Input Output.
11
S
First C Program (Cont…)
 Main Function
Main function is compulsory for any C program.
It is the “Entry Point or Start Point” of a program.
When a file is executed, from the main function the flow goes as per
our choice.
There may or may not be other functions written by us in a program.
void is a keyword.
After the main function has been declared, we have to specify the
opening and closing parentheses (Curly Brackets { }).
Semicolon “;” determines the end of the statement.

12
S
First C Program (Cont…)
 Main Function (Cont…)
printf(): It generates the output by passing the text written inside
double quotes. Syntax:
printf(“format string”, argument);
Format string can be %d, %c, etc.

scanf(): It is used to read an input data from the console. Syntax:


scanf(“format string”, argument);

13
S
First C Program (Cont…)
 How to Write/Run
Create a C program (Notepad or any other Text Editor) and save the
file as file_name.c.
Compile the program, which generates an .exe file (executable file).
Run the program.
The .exe file created after compilation is run and not the source file
i.e. .c file.
Different compiler supports different option for compiling and
running.

14
S
Compilation Process
 There are 4 phases through which a program transformed
into an executable form:
Preprocessor: The source code is first passed to the pre-processor.
The preprocessor expands this code, and then, this expanded code or
pre-processed code is passed to the compiler.
Compiler: The compiler converts the expanded 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’.
Linker: It combines the object code of library files with the object
code of our program. The output of the linker is the executable file.
15
S
Compilation Process (Cont…)

Fig. 1: Compilation process


16
S
Variable
A variable is a name given to a storage area that our
program can use.
 It is used to store data.
 Value of a variable can be changed and reused many times.
 Each variable in C has a specific type (int, char, etc.).
 Rules to define a variable’s name
Can have alphabets, digits, and underscore.
Can start with the alphabet and underscore only.
It cannot start with a digit.
No other special characters are allowed including space.
A variable name must not be any reserved word or Keyword.
17
S
Variable (Cont…)
 Valid variable
int x;
int a2002;

 Invalid variable
int 5;
int x y;
int if;

18
S
Variable (Cont…)
 Types of Variable
Local Variable: A variable that is declared inside the function or
block is called as a local variable.
void name(){
int x=10; //Local variable
}
Global Variable: A variable that is declared outside the function or
block is called as a global variable. The value of a global variable can
be modified by a function.
int value=20; //Global variable
void name(){
int x=10; //Local variable
} 19
S
Variable (Cont…)
 Types of Variable (Cont…)
Static Variable: A static variable is declared with the static keyword.
It is kept in the memory till the end of the program, whereas a normal
variable is destroyed, when a function is over.
The static variable inside the function holds the value not only till the
end of the function block, but till the end of the entire program.

20
S
Variable (Cont…)
 Types of Variable (Cont…)
External Variable: We can share a variable in multiple C source files
by using an external variable. To declare an external variable, we need
to use extern keyword.
external_file.h
extern int x=10; //External variable

external.c
#include “external_file.h”
#include <stdio.h>
void value()
{
printf(“External variable: %d”, x);
}
21
22

Comprehensive Examination 12/6/2022


S

Slides are prepared from various sources,


such as Book, Internet Links and many
more.

23

You might also like