SOFTWARE DEVELOPMENT IN C CM9041 - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

SOFTWARE DEVELOPMENT IN C CM9041

Description:

1 Lecture, 1 Tutorial , 1 Practical per week. Module Handbook contains details ... Cryptic syntax programs can be written quickly but can be difficult to read ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 19
Provided by: rho2
Category:

less

Transcript and Presenter's Notes

Title: SOFTWARE DEVELOPMENT IN C CM9041


1
SOFTWARE DEVELOPMENT IN CCM904-1
  • Lecture 1
  • Introduction to C

2
Module Structure
  • 1 Lecture, 1 Tutorial , 1 Practical per week
  • Module Handbook contains details
  • teaching team
  • class contact,
  • reading list
  • Assessment
  • Web site-www.soc.staffs.ac.uk/rgh1
  • lecture notes and practical exercises
  • Module handbook to download
  • Assignment details

3
Origins of C
  • 1971 Ritchie and Thompson develop Unix written in
    assembly language
  • This Unix wasnt portable, a suitable HLL with
    low level facilities was required
  • CPL had been developed in the 60s
  • CPL was a large language, later pared down -gt
    BCPL
  • Thompson further reduced BCPL -gt B
  • Ritchie enhanced B -gt C. Unix was rewritten in C
  • Unix C became widely available
  • Unix is now portable any machine with a C
    compiler can run Unix

4
C Standards and Variants
  • 1978 Kernighan Ritchie publish The C
    Programming Language (Traditional C)
  • 1990 ANSI Standard (ANSI C)
  • Anything written in traditional C will run on an
    ANSI C compiler
  • Also available Borland C, Microsoft C

5
Characteristics of C
  • Suitable for systems programming
  • Suitable for applications programming
  • Cryptic syntax programs can be written quickly
    but can be difficult to read
  • Permissive data typing gives flexibility but
    reduces the number of errors detected at
    compilation time

6
Developing a C Program
  • Fully understand the problem
  • Design a solution
  • Test
  • Implement in a suitable programming language
  • Test
  • Release
  • Maintain

7
Overall Structure of a C program
  • include ltstdio.hgt
  • DEFINITION OF ANY CONSTANTS
  • int main(void) / some explanatory comment /
  • DECLARATIONS
  • STATEMENTS
  • return 0

8
The Pre-Processor
C
Pure C
C Compiler
Object Code
Pre-processor
Object code is executed when the program runs
9
Data Types
  • Basic Data Types
  • int i,j 4 bytes
  • float x,y 4 bytes
  • double p,q 8 bytes
  • char c 1 byte (ASCII)

10
  • Sizeof Operator
  • int i declare an integer variable called i
  • sizeof(int) - Gives 4
  • sizeof(i) - Gives 4
  • Additional Data Types
  • long int 8 bytes (263 1) greater range
  • short int 2 bytes less storage
  • unsigned int 4 bytes greater range, positive
    numbers

11
More about the Structure of a C Program
  • The Function main
  • In C, all code is packaged in functions
  • main is the function that the system calls when
    you run your program
  • Every program must have one and only one main
  • All functions may return a value

Function 1
Function 2
Main statement Call function1 statement statement
Call function 2 return
12
Function Components
  • A function definition consists of two
  • parts
  •  A Specification ( or header or interface)
    Specifies the function name, the return value and
    argument list
  • A Body ( or block or implementation) Code to be
    executed when the function is called
  • A sequence of statements enclosed in braces

13
 Expressions and Statements
  • A section of code such as n1n2 is called an
    expression
  • A statement is a step in a program
  • An expression becomes a statement when it
  • is terminated by a semicolon

14
Comments
  • / An example of a C comment /
  • A multiline comment can also be used
  • /
  • This is a multiline
  • comment. Indentation is not compulsory
  • but it makes the code more readable
  • /

15
Consideration of two simple examples of a C
program
  • include ltstdio.hgt
  • define PI 3.14
  • int main(void) / calculates the area and the
    circumference of a circle of radius 3 /
  • int radius
  • float circum, area
  • radius3
  • circum2PIradius
  • areaPIradiusradius
  • printf(circumference f\n, circum)
  • printf(area f\n, area)
  • return 0

16
Output (printf statements)
  • The printf statement consists of any text to be
    printed plus a format specifier for each argument
  •  
  • Format Specifiers d, 6d, f, 6.2f, ld, lf,
    c, s
  •  
  • Special Character Constants for use in control
    strings
  • \n newline
  • \t tab
  • \\ backslash
  • \ single quote

17
Input (scanf statements)
  • Input
  • scanf() function is used
  • Format scanf(control string, arguments)
  • The arguments must be addresses
  • e.g.
  • int n
  • scanf(d, n)
  • The is used to obtain the address of n

18
include ltstdio.hgt define PI 3.14 int
main(void) / reads the radius of a circle and
then calculates its area and
circumference/ int radius float
circum,area printf(input radius
) scanf(d, radius) circum2PIradius area
PIradiusradius printf(\n\nresults\n\n) pri
ntf(Circle of radius d,radius) printf(\nCircu
mference f and area f\n, circum,area) return
0
Write a Comment
User Comments (0)
About PowerShow.com