Вы находитесь на странице: 1из 19

Session 1

Basics of ‘C’
Objectives
Explain the beginning of C
Explain why and when C is used
Discuss the C program structure
Discuss algorithms
Demonstrate use of flowcharts
Apply the rules for writing C program
Demonstrate compilation and execution of a C
program

Programming in C / Session 1 / 2 of 19
Problem Solving Approach
A step-by-step approach is used to solve any
problem
The step-by-step approach that is applied to
solve a problem may vary according to the
situation
The commonly used approaches are
Programs
Flow Charts
Algorithms

Programming in C / Session 1 / 3 of 19
Programs 2-1
Instructions grouped together in a sequential
manner is called a program.
Program helps perform a task or solve a
problem.
A program ensures that the task takes place
without any obstructions.
When the set of instructions are known, the
execution of the program takes place smoothly.

Programming in C / Session 1 / 4 of 19
Programs 2-2

 Here, the boss gives simple instructions in a sequential


manner to perform a task without interruptions.

Programming in C / Session 1 / 5 of 19
Flow Charts 3-1
Pictorial representation of the approach to
solving a problem, with use of standard set of
symbols, is a Flow Chart.
As a picture speaks better than words, drawing a
diagram will help the user understand the
solution easily.
The Flow chart can also help the user to
understand the correct flow of actions and steps
to follow.

Programming in C / Session 1 / 6 of 19
Flow Charts 3-2
Flow charts use a standard set of symbols.
Rectangles for processing
Diamond shapes for decision making
The symbols are accepted and understood
uniformly by all the programmers in the world.
Connectors are used to link flow charts that are
in multiple pages.
Any flow chart always has a START and STOP.

Programming in C / Session 1 / 7 of 19
Flow Charts 3-3
START Terminator Symbol: Used
here to begin the Flow chart

Accept num1 Input / Output Symbol: Used


and num 2 here to accept numbers

Process Symbol: Used here to


Result = multiply two numbers and
num1 * num2 obtain the result

Display Input / Output Symbol: Used


Result here to display the result

Terminator Symbol: Used


STOP here to end the Flow chart
Programming in C / Session 1 / 8 of 19
Algorithms
Formulation of an approach to solve a problem
in simple and understandable language is called
an algorithm.
Algorithm to calculate the area of a rectangle
Statements in algorithms clearly explain the
action that
1. Accept twoisvalues
to be from
performed
the user by
as that step.and
the length
The stepsofhave
breadth to be short and precise.
the rectangle.
2. Multiply the
Collection of length
theseand breadth
steps, to obtain
helps solve the
thearea.
3. Display the area.
problem.
Two different individuals can write two different
algorithms to achieve the same result.

Programming in C / Session 1 / 9 of 19
History of C 2-1
Languages like B, Combined Programming
Language (CPL) and Basic CPL were used
popularly.
The B language used earlier was added with
basic functionality of BCPL to create C language.
Dennis Ritchie developed C in 1972 while
working with Bell Laboratories.
C was developed on PDP – 11 computers.

Programming in C / Session 1 / 10 of 19
History of C 2-2
UNIX operating system was re-written using the
C language.
When UNIX was re-written, only a part of the
original assembly language was retained.
Most universities used UNIX and this helped
make C a popular language among students.
To avoid compatibility problems arising from the
variations of C language developed by different
companies, ANSI set the guidelines for
standardising C. This is called ANSI C.
Programming in C / Session 1 / 11 of 19
Applications of C
 The most popular example of C application is the re -
creation of UNIX operating system.
 C is used to develop compilers, interpreters, graphic and
general utilities.
 C has been used in the development of various
databases, word processors and spread sheets.
 Power and flexibility has prompted the use of C
language in the development of custom – made
applications like railway ticket vending machines and
applications in the banking and insurance sector.

Programming in C / Session 1 / 12 of 19
Structure of C program 2-1
A typical C program is as follows
#include<stdio.h> Pre-processor
command
main() Starting point of the program

{ Opening brace

printf("Hello World\n");
Prints Hello World
} Closing brace Programming in C / Session 1 / 13 of 19
Structure of C program 2–2
 Output of the program is

Programming in C / Session 1 / 14 of 19
Compiling 2-1
 There are four files associated when a C program is
compiled
 Source code – with ‘.c’ as the extension. It is the file
where the program instructions are written.
 Header File – contains the declaration of functions and
the pre-processor commands. It has ‘.h’ as its extension.
 Object Files – these are the files created by the compiler
and have a extension either as ‘.o’ or ‘.obj’.
 Binary Executables – output from the linking process.
The extension of these files is ‘.exe’.
 The linker is a program that collects all the related object
files and creates an executable file.
Programming in C / Session 1 / 15 of 19
Compiling 2-2
Source Code (User
written program)

Compile the Source Code

Object File created.


But not executed

Link the object files to


create an executable file

Executable File for


execution

Programming in C / Session 1 / 16 of 19
Project in Visual C++
Creating a new file and saving it in the proper
directory.
Writing the C program in the IDE.
Building the project.
Executing the project.
Closing the project.

Demonstration
The steps involved in creating a project in Visual C++

Programming in C / Session 1 / 17 of 19
Summary 2-1
Algorithms help achieve a task with the help of
well-defined statements.
Algorithms can be pictorial or graphically
presented by flow charts.
For easy understanding of the depicted flow
charts, a standards set of symbols is used
across the industry.
Sequentially grouped set of instructions for
performing a task is called a Program.

Programming in C / Session 1 / 18 of 19
Summary 2-2
C language is extremely powerful and flexible as
it exhibits the features of both second and third
generation languages.
Compiler converts a program into a program
understood by the machine.
Linker is a program that links related object files
to create an executable program.

Programming in C / Session 1 / 19 of 19

Вам также может понравиться