01introduction To C Programming
01introduction To C Programming
Facts of c
Why to use c
Program structure
C programming in embedded system
Compilation process
Getting started to Local environment setup
Raghavendran S
Resource Person(RPA)
NIELIT Chennai
The C programming language is a general-purpose, high-
level language that was originally developed by Dennis M.
Ritchie to develop the UNIX operating system at Bell Labs. C
was originally first implemented on the DEC PDP-11
computer in 1972.
In 1978, Brian Kernighan and Dennis Ritchie produced the
first publicly available description of C, now known as the
K&R standard.
The UNIX operating system, the C compiler, and essentially
all UNIX applications programs have been written in C.
The C has now become a widely used professional language
for various reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It can handle low-level activities.
• It can be compiled on a variety of computer platforms
NIELIT CHENNAI 2
C was invented to write an operating system called
UNIX.
C is a successor of B language which was introduced
around the early 1970s.
The language was formalized in 1988 by the American
National Standard Institute (ANSI).
The UNIX OS was totally written in C.
Today C is the most widely used and popular System
Programming Language.
Most of the state-of-the-art software have been
implemented using C.
Today's most popular Linux OS and RDBMS MySQL have
been written in C.
NIELIT CHENNAI 3
C was initially used for system development
work, in particular the programs that make up
the operating system. C was adopted as a system
development language because it produces code
that runs nearly as fast as code written in
assembly language.
Some examples of the use of C might be:
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases etc
NIELIT CHENNAI 4
ANSI C standard emerged in the early 1980s, this was split into two
titles
The original was still called Programming in C, and the title that
covered ANSI C was called Programming in ANSI C.
This was done because it took several years for the compiler vendors to
release their ANSI C compilers and for them to become ubiquitous.
It was initially designed for programming UNIX operating system.
Now the software tool as well as the C compiler is written in C.
Major parts of popular operating systems like Windows, UNIX, Linux is
still written in C. This is because even today when it comes to
performance (speed of execution) nothing beats C.
Moreover, if one is to extend the operating system to work with new
devices one needs to write device driver programs. These programs are
exclusively written in C. C seems so popular is because it is reliable,
simple and easy to use. often heard today is – “C has been already
succeeded by languages like C++, C# and Java.
NIELIT CHENNAI 5
Alphabets Constant
Digits Variable
Special Keyword Instruction Program
symbols
NIELIT CHENNAI 6
Direct access to low level hardware API's. which can provide you
nearly as much control over resources as much assembly language
does
You can find a C compiler for the vast majority of these devices.
NIELIT CHENNAI 7
C is a general-purpose programming
language, which is widely used to design
any type of desktop-based applications.
The main features of C language include
low-level access to memory, a simple set of
keywords are features make C language
suitable for system programming like OS or
compiler development.
NIELIT CHENNAI 8
C Embedded c
C is a general-purpose Embedded C is simply an extension C
programming language, which is language and it is used to develop
widely used to design any type of micro-controller based applications.
desktop-based applications.
Input can be given to the Only the pre-defined input can be given
program while it is running. to the running program.
NIELIT CHENNAI 9
There are 3 level of language
Low level language
Middle level language
High level language
NIELIT CHENNAI 10
Two types
Procedure oriented programming language
(pop).
Object oriented programming language (oops)
NIELIT CHENNAI 11
The c program involves in following sections
comment section
Preprocessor directive
Global declarations [definition]
Main function
local variables
program statements & expression
User defined function
NIELIT CHENNAI 12
NIELIT CHENNAI 13
Incomments section the user can able to
read and understand various element in
program
There are two types of comments
Single line comments (//)
Multi line comments (/* */)
NIELIT CHENNAI 14
This section is used to link the external header files
which are pre-defined function available in program
Files can be included by using “include”
Eg include <stdio.h>
“Stdio” means standard inputs and outputs.
NIELIT CHENNAI 15
Some variables are declared globally so that
it can be access by all functions used in the
program
This section must be declared outside the
main function
NIELIT CHENNAI 16
Itis the user defined function and every
function has one main() function from
where actually program starts
NIELIT CHENNAI 17
Main function contain two parts
1.Declaration part
Here we declare all variable that will
be used program
2.execution part
which includes all statements that we
want to execute
NIELIT CHENNAI 18
A compiler convers a ‘C’ program into an
executable program..
how the source code of a program is converted to
an executable binary image. Keep in mind that this
is a very simplistic exposition of a complex process.
There are three key programs that convert the code
from text to executable:
The compiler
assembler
linker.
NIELIT CHENNAI 19
The pre-processor performs a number of text-
conversion and text-replacement tasks.
It includes information from header-files, replaces
symbolic constants, and expands macros.
The first phase through which source code is
passed.
The lexical analyser reads the pre-processed file,
which is still a string of unprocessed
characters,and interprets the characters as tokens
(such as keywords, operators, variable names,
etc).
This phase include
Removal of comments
Expansion of macros
Expansion of included files
NIELIT CHENNAI 20
A compilers is what that takes the code and translate
it into the machine code (i.e) 0’s 1’s
The process of converting high-level programs into a
machine language is called as compilation
A compiler read a source file, translate everything
into machine code and write out executable
The compiler back-end converts the expression trees
to assembler code. This code is low-level machine
dependent instructions.
NIELIT CHENNAI 21
Anassembler is a program that converts
assembly language into machine code
Most programs are written in high-level
programming languages and are
compiled directly to machine code using a
compiler.
NIELIT CHENNAI 22
The linker merges object code produced
from all the source files composing the
program, along with code from any
libraries that might be included in the
program. The result is a binary
“executable image” of the program.
Linking is performed by a linker, which is
often part of a compiler.
NIELIT CHENNAI 23
The process of editing, compiling,running and
debugging programs is often managed by a
single integrated application known as
integrated development environment or IDE
An Ide is a windows-based program that allows
us to easily manage large software
programs,edit files in windows and compile
link run and debug program
Examples
NIELIT CHENNAI 24
NIELIT CHENNAI 25
pwd —To know which directory you are in, you can use
the “pwd” command.
NIELIT CHENNAI 26
cd — Use the "cd" command to go to a directory. For
example, if you are in the home folder, and you want to
go to the downloads folder, then you can type in “cd
Downloads”.
NIELIT CHENNAI 27
rm - Use the rm command to delete files and
directories. Use "rm -r" to delete just the directory. It
deletes both the folder and the files it contains when
using only the rm command.
NIELIT CHENNAI 28
cp — Use the cp command to copy files through the command
line. It takes two arguments: The first is the location of the file to
be copied, the second is where to copy.
NIELIT CHENNAI 29
man & --help — To know more about a command and how to
use it, use the man command. It shows the manual pages of the
command.
NIELIT CHENNAI 30
NIELIT CHENNAI 31
Vi Editor:
Vi will be default.
$vi
$ gedit
NIELIT CHENNAI 32
A Compiler is a software that typically takes a high level
language code as input and converts it to a lower level
language.
When you compile a source file (.c), it generates an
object file (.o).
NIELIT CHENNAI 33
nielie$ ls
eg.c
nielit$ gcc eg.c this command will give a.out
( assembler output) file
nielit$ ls
a.out eg.c
nielit$ ./a.out can be executed by “ ./a.out “
hello world
nielit$ gcc -o eg.o eg.c we can give name to our object file
nielit$ ls
a.out eg.c eg.o
nielit$ ./eg.o command to execute the program
hello world
NIELIT CHENNAI 34
NIELIT CHENNAI 35