B.Bhuvaneswaran, AP (SG) / CSE
9791519152
bhuvaneswaran@rajalakshmi.edu.in
Programming Logic
Overview of C
Overview of C
Overview of C Rajalakshmi Engineering College 2
Rajalakshmi Engineering College 2
Basics of C Language
 C language was developed by Dennis Ritchie of Bell Laboratories in
New Jersey in the year 1972.
 The language was named as C because it was the successor of
another language called B.
Overview of C
Overview of C Rajalakshmi Engineering College 3
Rajalakshmi Engineering College 3
Compilers Vs Interpreters
Compilers Interpreters
A compiler reads entire program
and converts it to the object
code.
An interpreter reads only one line
of source program at a time and
converts it to object code.
It provides errors not of a single
line but errors of the entire
program.
In case of any error, the same will
be indicated instantly.
It consumes little time for
converting a source program to
an object program.
It is more time-consuming for
converting a source program to
an object program.
Example: C Compiler Example: BASIC
Overview of C
Overview of C Rajalakshmi Engineering College 4
Rajalakshmi Engineering College 4
Compilers Vs Interpreters
Overview of C
Overview of C Rajalakshmi Engineering College 5
Rajalakshmi Engineering College 5
History of ANSI C
Overview of C
Overview of C Rajalakshmi Engineering College 6
Rajalakshmi Engineering College 6
Procedure-oriented Programming
 C is commonly known as procedure-oriented programming (POP).
 In the procedure-oriented approach, the problem is viewed as a
sequence of things to be done such as reading, calculating and
printing.
 A number of functions are written to accomplish these tasks.
 The primary focus is on functions.
 The technique of hierarchical decomposition has been used to
specify the tasks to be completed for solving a problem.
Overview of C
Overview of C Rajalakshmi Engineering College 7
Rajalakshmi Engineering College 7
Typical Structure of POP
Overview of C
Overview of C Rajalakshmi Engineering College 8
Rajalakshmi Engineering College 8
Relationship of Data & Functions in POP
Overview of C
Overview of C Rajalakshmi Engineering College 9
Rajalakshmi Engineering College 9
Features of C Language
C
Language
Portability
Modularity
Flexibility
Speed
Extensibility
Compactness
Case Sensitive
Overview of C
Overview of C Rajalakshmi Engineering College 10
Rajalakshmi Engineering College 10
Basic Structure of C Programs
Overview of C
Overview of C Rajalakshmi Engineering College 11
Rajalakshmi Engineering College 11
Documentation Section
 The documentation section consists of a set of comment lines
giving the name of the program, the author and other details,
which the programmer would like to use later.
Overview of C
Overview of C Rajalakshmi Engineering College 12
Rajalakshmi Engineering College 12
Link Section
 The link section provides instructions to the compiler to link
functions from the system library.
Overview of C
Overview of C Rajalakshmi Engineering College 13
Rajalakshmi Engineering College 13
Definition Section
 The definition section defines all symbolic constants.
Overview of C
Overview of C Rajalakshmi Engineering College 14
Rajalakshmi Engineering College 14
Global Declaration Section
 There are some variables that are used In more than one function.
 Such variables are called global variables and are declared in the
global declaration section that is outside of all the functions.
 This section also declares all the user–defined functions.
Overview of C
Overview of C Rajalakshmi Engineering College 15
Rajalakshmi Engineering College 15
main() function Section
 Every C program must have one main() function section.
 This section contains two parts:
• declaration part and
• executable part.
Overview of C
Overview of C Rajalakshmi Engineering College 16
Rajalakshmi Engineering College 16
main() function Section
 The declaration part declares all the variables used in the
executable part.
 There is at least one statement in the executable part.
 These two parts must appear between the opening and the
closing braces.
 The program execution begins at the opening brace and ends at
the closing brace.
 The closing brace of the main function section is the logical end of
the program.
 All statements in the declaration and executable parts end with a
semicolon(;).
Overview of C
Overview of C Rajalakshmi Engineering College 17
Rajalakshmi Engineering College 17
Sub program Section
 The subprogram section contains all the user–defined functions
that are called In the main function.
 User–defined functions are generally placed immediately after the
main function, although they may appear in any order.
Overview of C
Overview of C Rajalakshmi Engineering College 18
Rajalakshmi Engineering College 18
Important Note
 All sections, except the main function section may be absent when
they are not required.
Overview of C
Overview of C Rajalakshmi Engineering College 19
Rajalakshmi Engineering College 19
Executing a C Program
 Executing a program written in C involves a series of steps. These
are:
• Creating the program;
• Compiling the program;
• Linking the program with functions that are needed from the C library; and
• Executing the program.
Overview of C
Overview of C Rajalakshmi Engineering College 20
Rajalakshmi Engineering College 20
Compiling and Running a C Program
Overview of C
Overview of C Rajalakshmi Engineering College 21
Rajalakshmi Engineering College 21
Compilation of Multiple Files
Overview of C
Overview of C Rajalakshmi Engineering College 22
Rajalakshmi Engineering College 22
Header Files
 A header file is a file with extension .h which contains C function
declarations and macro definitions to be shared between several
source files.
 There are two types of header files:
• the files that the programmer writes and
• the files that come with C compiler.
 The header file is linked to the code by:
• #include <stdio.h>
Overview of C
Overview of C Rajalakshmi Engineering College 23
Rajalakshmi Engineering College 23
Header Files
Overview of C
Overview of C Rajalakshmi Engineering College 24
Rajalakshmi Engineering College 24
stdio.h
 All formatted and unformatted functions include file operation
functions defined in this file.
 The most useful formatted printf() and scanf() are defined in this
file.
 Most useful functions from this header files are printf(), scanf(),
getchar(), gets(), putc() and putchar().
Overview of C
Overview of C Rajalakshmi Engineering College 25
Rajalakshmi Engineering College 25
List of Header Files
alloc.h assert.h bcd.h bios.h complex.h
conio.h ctype.h dir.h dirent.h dos.h
errno.h fcntl.h float.h fstream.h generic.h
graphics.h io.h iomanip.h iostream.h limits.h
locale.h malloc.h math.h mem.h process.h
setjmp.h share.h signal.h stdarg.h stddef.h
stdio.h stdiostr.h stdlib.h stream.h string.h
strstrea.h sysstat.h systimeb.h systypes.h time.h
values.h
Overview of C
Overview of C Rajalakshmi Engineering College 26
Rajalakshmi Engineering College 26
Comments
 Comments are used to document programs and improves
readability.
 In C a comment will start with /* and ends with */.
 The C Compilers ignores the comments.
 Compilers do not provide any machine language object code for
the comments.
 Syntax:
/* Comments */
Overview of C
Overview of C Rajalakshmi Engineering College 27
Rajalakshmi Engineering College 27
Examples
/* This is a single line comment */
/* This is a multiline
* comment in C */
/******************************************************
* This style of commenting is used for functions
******************************************************/
Overview of C
Overview of C Rajalakshmi Engineering College 28
Rajalakshmi Engineering College 28
Code Indentation
 Indentation is the practice by Software Engineers to use spaces or
tabs (4 spaces) consistently in every line of code to group lines
together based on their scope for easy readability.
 An indented code looks better and can be understood easily.
Overview of C
Overview of C Rajalakshmi Engineering College 29
Rajalakshmi Engineering College 29
Algorithm
 Algorithm is an ordered sequence of finite, well defined,
unambiguous instructions for completing a task.
 Algorithm is an English-like representation of the logic which is
used to solve the problem.
 It is a step- by-step procedure for solving a task or a problem.
 The steps must be ordered, unambiguous and finite in number.
Overview of C
Overview of C Rajalakshmi Engineering College 30
Rajalakshmi Engineering College 30
Algorithm-Greatest of 3 Nos.-Alg. -1
Step 1: Start
Step 2: Read the three numbers A, B, C
Step 3: Compare A and B. If A is greater perform step 4 else perform
step 5.
Step 4: Compare A and C. If A is greater, output “A is greatest” else
output “C is greatest”. Perform step 6.
Step 5: Compare B and C. If B is greater, output “B is greatest” else
output “C is greatest”.
Step 6: Stop
Overview of C
Overview of C Rajalakshmi Engineering College 31
Rajalakshmi Engineering College 31
Algorithm-Greatest of 3 Nos.-Alg. -2
Step 1: Start
Step 2: Read the three numbers A, B, C
Step 3: Compare A and B. If A is greater, store A in MAX, else store B
in MAX.
Step 4: Compare MAX and C. If MAX is greater, output “MAX is
greatest” else output “C is greatest”.
Step 5: Stop
Overview of C
Overview of C Rajalakshmi Engineering College 32
Rajalakshmi Engineering College 32
Flowchart
 A flowchart is a diagrammatic representation of the logic for
solving a task.
 A flowchart is drawn using boxes of different shapes with lines
connecting them to show the flow of control.
 The purpose of drawing a flowchart is to make the logic of the
program clearer in a visual form.
Overview of C
Overview of C Rajalakshmi Engineering College 33
Rajalakshmi Engineering College 33
Flowchart Symbols
Overview of C
Overview of C Rajalakshmi Engineering College 34
Rajalakshmi Engineering College 34
Pseudocode
 Pseudo code consists of short, readable and formally-styled
English language used for explaining an algorithm.
 Pseudo code does not include details like variable declarations,
subroutines etc.
 Pseudo code is a short-hand way of describing a computer
program.
Overview of C
Overview of C Rajalakshmi Engineering College 35
Rajalakshmi Engineering College 35
Examples of Pseudocode
Overview of C
Overview of C Rajalakshmi Engineering College 36
Rajalakshmi Engineering College 36
Online C/C++ Compilers
 https://ideone.com/
 http://codepad.org/
 https://www.codechef.com/ide
 https://www.jdoodle.com/c-online-compiler/
 https://www.onlinegdb.com/
 https://godbolt.org/
Overview of C
Overview of C Rajalakshmi Engineering College 37
Rajalakshmi Engineering College 37
C/C++ IDEs
 https://www.eclipse.org/downloads/download.php?file=/technol
ogy/epp/downloads/release/2020-03/R/eclipse-cpp-2020-03-R-
incubation-win32-x86_64.zip
 https://www.fosshub.com/Code-Blocks.html?dwl=codeblocks-
20.03-setup.exe
 https://aka.ms/win32-x64-user-stable
 https://downloads.codelite.org/downloads.php?windows_weekly
_64
 https://www.apache.org/dyn/closer.cgi/netbeans/netbeans/11.3/
netbeans-11.3-bin.zip
 https://bloodshed-dev-c.en.softonic.com/support
Thank You

C Programming-Lecture Notes-01-Overview of C.pdf

  • 1.
    B.Bhuvaneswaran, AP (SG)/ CSE 9791519152 [email protected] Programming Logic Overview of C
  • 2.
    Overview of C Overviewof C Rajalakshmi Engineering College 2 Rajalakshmi Engineering College 2 Basics of C Language  C language was developed by Dennis Ritchie of Bell Laboratories in New Jersey in the year 1972.  The language was named as C because it was the successor of another language called B.
  • 3.
    Overview of C Overviewof C Rajalakshmi Engineering College 3 Rajalakshmi Engineering College 3 Compilers Vs Interpreters Compilers Interpreters A compiler reads entire program and converts it to the object code. An interpreter reads only one line of source program at a time and converts it to object code. It provides errors not of a single line but errors of the entire program. In case of any error, the same will be indicated instantly. It consumes little time for converting a source program to an object program. It is more time-consuming for converting a source program to an object program. Example: C Compiler Example: BASIC
  • 4.
    Overview of C Overviewof C Rajalakshmi Engineering College 4 Rajalakshmi Engineering College 4 Compilers Vs Interpreters
  • 5.
    Overview of C Overviewof C Rajalakshmi Engineering College 5 Rajalakshmi Engineering College 5 History of ANSI C
  • 6.
    Overview of C Overviewof C Rajalakshmi Engineering College 6 Rajalakshmi Engineering College 6 Procedure-oriented Programming  C is commonly known as procedure-oriented programming (POP).  In the procedure-oriented approach, the problem is viewed as a sequence of things to be done such as reading, calculating and printing.  A number of functions are written to accomplish these tasks.  The primary focus is on functions.  The technique of hierarchical decomposition has been used to specify the tasks to be completed for solving a problem.
  • 7.
    Overview of C Overviewof C Rajalakshmi Engineering College 7 Rajalakshmi Engineering College 7 Typical Structure of POP
  • 8.
    Overview of C Overviewof C Rajalakshmi Engineering College 8 Rajalakshmi Engineering College 8 Relationship of Data & Functions in POP
  • 9.
    Overview of C Overviewof C Rajalakshmi Engineering College 9 Rajalakshmi Engineering College 9 Features of C Language C Language Portability Modularity Flexibility Speed Extensibility Compactness Case Sensitive
  • 10.
    Overview of C Overviewof C Rajalakshmi Engineering College 10 Rajalakshmi Engineering College 10 Basic Structure of C Programs
  • 11.
    Overview of C Overviewof C Rajalakshmi Engineering College 11 Rajalakshmi Engineering College 11 Documentation Section  The documentation section consists of a set of comment lines giving the name of the program, the author and other details, which the programmer would like to use later.
  • 12.
    Overview of C Overviewof C Rajalakshmi Engineering College 12 Rajalakshmi Engineering College 12 Link Section  The link section provides instructions to the compiler to link functions from the system library.
  • 13.
    Overview of C Overviewof C Rajalakshmi Engineering College 13 Rajalakshmi Engineering College 13 Definition Section  The definition section defines all symbolic constants.
  • 14.
    Overview of C Overviewof C Rajalakshmi Engineering College 14 Rajalakshmi Engineering College 14 Global Declaration Section  There are some variables that are used In more than one function.  Such variables are called global variables and are declared in the global declaration section that is outside of all the functions.  This section also declares all the user–defined functions.
  • 15.
    Overview of C Overviewof C Rajalakshmi Engineering College 15 Rajalakshmi Engineering College 15 main() function Section  Every C program must have one main() function section.  This section contains two parts: • declaration part and • executable part.
  • 16.
    Overview of C Overviewof C Rajalakshmi Engineering College 16 Rajalakshmi Engineering College 16 main() function Section  The declaration part declares all the variables used in the executable part.  There is at least one statement in the executable part.  These two parts must appear between the opening and the closing braces.  The program execution begins at the opening brace and ends at the closing brace.  The closing brace of the main function section is the logical end of the program.  All statements in the declaration and executable parts end with a semicolon(;).
  • 17.
    Overview of C Overviewof C Rajalakshmi Engineering College 17 Rajalakshmi Engineering College 17 Sub program Section  The subprogram section contains all the user–defined functions that are called In the main function.  User–defined functions are generally placed immediately after the main function, although they may appear in any order.
  • 18.
    Overview of C Overviewof C Rajalakshmi Engineering College 18 Rajalakshmi Engineering College 18 Important Note  All sections, except the main function section may be absent when they are not required.
  • 19.
    Overview of C Overviewof C Rajalakshmi Engineering College 19 Rajalakshmi Engineering College 19 Executing a C Program  Executing a program written in C involves a series of steps. These are: • Creating the program; • Compiling the program; • Linking the program with functions that are needed from the C library; and • Executing the program.
  • 20.
    Overview of C Overviewof C Rajalakshmi Engineering College 20 Rajalakshmi Engineering College 20 Compiling and Running a C Program
  • 21.
    Overview of C Overviewof C Rajalakshmi Engineering College 21 Rajalakshmi Engineering College 21 Compilation of Multiple Files
  • 22.
    Overview of C Overviewof C Rajalakshmi Engineering College 22 Rajalakshmi Engineering College 22 Header Files  A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files.  There are two types of header files: • the files that the programmer writes and • the files that come with C compiler.  The header file is linked to the code by: • #include <stdio.h>
  • 23.
    Overview of C Overviewof C Rajalakshmi Engineering College 23 Rajalakshmi Engineering College 23 Header Files
  • 24.
    Overview of C Overviewof C Rajalakshmi Engineering College 24 Rajalakshmi Engineering College 24 stdio.h  All formatted and unformatted functions include file operation functions defined in this file.  The most useful formatted printf() and scanf() are defined in this file.  Most useful functions from this header files are printf(), scanf(), getchar(), gets(), putc() and putchar().
  • 25.
    Overview of C Overviewof C Rajalakshmi Engineering College 25 Rajalakshmi Engineering College 25 List of Header Files alloc.h assert.h bcd.h bios.h complex.h conio.h ctype.h dir.h dirent.h dos.h errno.h fcntl.h float.h fstream.h generic.h graphics.h io.h iomanip.h iostream.h limits.h locale.h malloc.h math.h mem.h process.h setjmp.h share.h signal.h stdarg.h stddef.h stdio.h stdiostr.h stdlib.h stream.h string.h strstrea.h sysstat.h systimeb.h systypes.h time.h values.h
  • 26.
    Overview of C Overviewof C Rajalakshmi Engineering College 26 Rajalakshmi Engineering College 26 Comments  Comments are used to document programs and improves readability.  In C a comment will start with /* and ends with */.  The C Compilers ignores the comments.  Compilers do not provide any machine language object code for the comments.  Syntax: /* Comments */
  • 27.
    Overview of C Overviewof C Rajalakshmi Engineering College 27 Rajalakshmi Engineering College 27 Examples /* This is a single line comment */ /* This is a multiline * comment in C */ /****************************************************** * This style of commenting is used for functions ******************************************************/
  • 28.
    Overview of C Overviewof C Rajalakshmi Engineering College 28 Rajalakshmi Engineering College 28 Code Indentation  Indentation is the practice by Software Engineers to use spaces or tabs (4 spaces) consistently in every line of code to group lines together based on their scope for easy readability.  An indented code looks better and can be understood easily.
  • 29.
    Overview of C Overviewof C Rajalakshmi Engineering College 29 Rajalakshmi Engineering College 29 Algorithm  Algorithm is an ordered sequence of finite, well defined, unambiguous instructions for completing a task.  Algorithm is an English-like representation of the logic which is used to solve the problem.  It is a step- by-step procedure for solving a task or a problem.  The steps must be ordered, unambiguous and finite in number.
  • 30.
    Overview of C Overviewof C Rajalakshmi Engineering College 30 Rajalakshmi Engineering College 30 Algorithm-Greatest of 3 Nos.-Alg. -1 Step 1: Start Step 2: Read the three numbers A, B, C Step 3: Compare A and B. If A is greater perform step 4 else perform step 5. Step 4: Compare A and C. If A is greater, output “A is greatest” else output “C is greatest”. Perform step 6. Step 5: Compare B and C. If B is greater, output “B is greatest” else output “C is greatest”. Step 6: Stop
  • 31.
    Overview of C Overviewof C Rajalakshmi Engineering College 31 Rajalakshmi Engineering College 31 Algorithm-Greatest of 3 Nos.-Alg. -2 Step 1: Start Step 2: Read the three numbers A, B, C Step 3: Compare A and B. If A is greater, store A in MAX, else store B in MAX. Step 4: Compare MAX and C. If MAX is greater, output “MAX is greatest” else output “C is greatest”. Step 5: Stop
  • 32.
    Overview of C Overviewof C Rajalakshmi Engineering College 32 Rajalakshmi Engineering College 32 Flowchart  A flowchart is a diagrammatic representation of the logic for solving a task.  A flowchart is drawn using boxes of different shapes with lines connecting them to show the flow of control.  The purpose of drawing a flowchart is to make the logic of the program clearer in a visual form.
  • 33.
    Overview of C Overviewof C Rajalakshmi Engineering College 33 Rajalakshmi Engineering College 33 Flowchart Symbols
  • 34.
    Overview of C Overviewof C Rajalakshmi Engineering College 34 Rajalakshmi Engineering College 34 Pseudocode  Pseudo code consists of short, readable and formally-styled English language used for explaining an algorithm.  Pseudo code does not include details like variable declarations, subroutines etc.  Pseudo code is a short-hand way of describing a computer program.
  • 35.
    Overview of C Overviewof C Rajalakshmi Engineering College 35 Rajalakshmi Engineering College 35 Examples of Pseudocode
  • 36.
    Overview of C Overviewof C Rajalakshmi Engineering College 36 Rajalakshmi Engineering College 36 Online C/C++ Compilers  https://ideone.com/  http://codepad.org/  https://www.codechef.com/ide  https://www.jdoodle.com/c-online-compiler/  https://www.onlinegdb.com/  https://godbolt.org/
  • 37.
    Overview of C Overviewof C Rajalakshmi Engineering College 37 Rajalakshmi Engineering College 37 C/C++ IDEs  https://www.eclipse.org/downloads/download.php?file=/technol ogy/epp/downloads/release/2020-03/R/eclipse-cpp-2020-03-R- incubation-win32-x86_64.zip  https://www.fosshub.com/Code-Blocks.html?dwl=codeblocks- 20.03-setup.exe  https://aka.ms/win32-x64-user-stable  https://downloads.codelite.org/downloads.php?windows_weekly _64  https://www.apache.org/dyn/closer.cgi/netbeans/netbeans/11.3/ netbeans-11.3-bin.zip  https://bloodshed-dev-c.en.softonic.com/support
  • 38.