Topic4 Introductory Computer Programming Language C - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

Topic4 Introductory Computer Programming Language C

Description:

Topic4 Introductory Computer Programming Language C. Introduction. A ... ampersand operator&: to access the address of a variable. Pointer arithmetic operation: ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 41
Provided by: CSU157
Category:

less

Transcript and Presenter's Notes

Title: Topic4 Introductory Computer Programming Language C


1
Topic4 Introductory Computer Programming Language
C
  • Introduction
  • A Simple Input and Output Program
  • Running a C Program
  • Control Flow and Data Structures
  • A Program Composed of Several Functions
  • Running Single File Programs

2
Programming Languages
  • Low level programming languages
  • Machine language
  • Assembly language
  • High level programming languages
  • Basic, Fortran, Cobol, PL/1, Pascal
  • C, C,Java
  • Macro Languages Nuc Med Appl.

3
C Language Functions
  • Main reserved for main program
  • int by default. Others must be defined. Void
    procedures
  • Subprogram gt functions
  • Variable name up and lower case.
  • Data types int, float, double, char.
  • Qualifiers int, long, short, unsigned

4
(No Transcript)
5
(No Transcript)
6
Statements
  • Assignment Statements
  • variableexpression
  • All Statements in C Return a Value
  • a3 /assign a the value 3 /
  • ba3 /assign b the value of a3 which is 3/
  • printf (d \n, b4)
  • / assign b the value 4 and print the result of
    the assignment which is 4 /

7
Operators
  • Operators , /, , -
  • Increment , decrement --
  • I increment I and then use its value in the
    expression, I use the value I and then
    increment it.
  • Example
  • int I,j,k
  • I3j10
  • jI / j is now 4, I is now 4 /
  • j1 I7 j(I)-5 / j is now 2, I is now 8 /
  • k--Ij /k is now 7214, I is 7, j is 3 /

8
Assignment Operators
  • Assignment Operators
  • Variablevariable OP expression gt Variable OP
    expression Example x3 gt x x3
  • Data Initialisation
  • int I2 j6
  • float x1.2
  • char cs
  • Blocks
  • A group of statements as a single entity does
    not need a semi-colon value of the block last
    statement executed.

9
Control Flow
  • Control Flow
  • selection if-then-else.
  • Loops while, for.
  • Switch multiway
  • Selection
  • if (integer - expression) block1 else block2
  • While Loops
  • while (integer - expression) while block
  • Do-While Loops
  • do do-while-block while (integer expression)

10
For Loops
  • For (expression1 expression2expression3)
  • For block
  • expression1 is evaluated before the loop is
    entered.
  • expression2 is the loop control loop continues
    if it is true.
  • Expression3 is executed at the end of each
    iteration.

11
(No Transcript)
12
(No Transcript)
13
(No Transcript)
14
(No Transcript)
15
Variables
  • Global variable
  • scope a global variable declared in the same
    file
  • not in a file external
  • external variable
  • use external if the global is defined below the
    function
  • static variable
  • keep a variable when function is returned.
  • Static for global variable keep the variable
    local to the file.

16
(No Transcript)
17
(No Transcript)
18
(No Transcript)
19
Pointer
  • Pointer
  • a variable that contains the address of other
    variable
  • ampersand operator to access the address of a
    variable.
  • Pointer arithmetic operation
  • increment or decrement by the size of the item it
    points to. I.e. 4 integer

20
(No Transcript)
21
Array
  • Array
  • name of the array is a pointer to the base
    address of the array.
  • Square bracket.
  • Array Initialisation
  • int a56,9,5,20,30

22
(No Transcript)
23
(No Transcript)
24
Character String
  • Character String array of character. Null
    character as a terminator
  • Multi-dimensional arrays
  • int a510 / 5 rows, 10 columns /
  • int I
  • Ia34 /Example of normal array indexing /

25
(No Transcript)
26
The C Preprocessor
  • Before C Program Compilation
  • include, define
  • stdio.h
  • example
  • define ARRAY_SIZE 10 / change size here /
  • int aARRAY_SIZE

27
Input and Output
  • printf (format-string, arg1, arg2, )
  • format d
  • special characters \n, \t.
  • scanf

28
(No Transcript)
29
(No Transcript)
30
(No Transcript)
31
(No Transcript)
32
User Defined Types
  • Enumerated Type
  • enum name enumerator1, enumerator2,
  • include ltstdio.hgt
  • enum colour red, orange, yellow, green, blue,
    violet
  • main()
  • enum colour my_suit_colour
  • my_suit_colourorange / no taste, but legal /
  • printf(my suit colour is d \n,
    my_suit_colour)

33
Structures
  • Treat a set of variables of different types as a
    single entity.
  • Struct type_name
  • type var_name1, var_name2,
  • type var_name3, var_name4,
  • Accessing Structures
  • current_time.hour
  • operator -gt

34
(No Transcript)
35
(No Transcript)
36
Union
  • Referencing the same storage location in
    different ways
  • Union name
  • type var1, var2,
  • type var3, var4,

37
(No Transcript)
38
Command Line Arguments
  • Argc number of arguments
  • argv values of arguments

39
(No Transcript)
40
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com