Topics to be covered - PowerPoint PPT Presentation

About This Presentation
Title:

Topics to be covered

Description:

Topics to be covered Program Structure Constants Variables Assignment Statements Standard Output Standard Input Math Functions Character Functions System Limitations – PowerPoint PPT presentation

Number of Views:105
Avg rating:3.0/5.0
Slides: 13
Provided by: Willi711
Category:

less

Transcript and Presenter's Notes

Title: Topics to be covered


1
Topics to be covered
  • Program Structure
  • Constants
  • Variables
  • Assignment Statements
  • Standard Output
  • Standard Input
  • Math Functions
  • Character Functions
  • System Limitations
  • Algorithm Development
  • Conditional Expressions
  • Selection Statements
  • Loop Structures

2
Structured Programming
  • Structured Programming
  • Combination of
  • Sequences
  • Selections
  • Loops
  • Sequences
  • Series of operations that are performed in order.
  • Selections
  • Choose one path from two or more possible paths.
  • Loops
  • Execute a block of code repeatedly as long as
    some condition is met.

3
Basic Flowcharting Elements
Arrows show the flow - cannot diverge but can
converge.
Execution Block
Selection Block
Entry Point
Exit Point
Input/Output Block
4
Selection Statements
  • Selectively choose one path of execution.
  • Based on the evaluation of a test.
  • Logical Test outcome is either TRUE or FALSE.
  • FALSE if expression evaluates to ZERO.
  • TRUE if expression evaluates to ANYTHING else.
  • Three varieties of selection statements.
  • if()/else
  • switch()
  • ()? (conditional or ternary operator)

5
Conditional Expressions
  • (test)
  • May be ANY expression that evaluates to a value.
  • logical operator (!, , )
  • relational operator (,!),(gt, lt), (lt,gt)
  • assignment operator (equal to value assigned)
  • single variable (or constant)
  • function return value
  • Test outcome is either TRUE or FALSE.
  • FALSE if expression evaluates to ZERO - exactly.
  • TRUE if expression evaluates to ANYTHING else.

6
if() and if()/else statements
  • Syntax
  • if(test)
  • if_code
  • else
  • else_code

7
()? - conditional or ternary operator
  • Syntax
  • x (test)? if_exprelse_expr
  • Shorthand version of if()/else

8
switch() statement
  • Syntax
  • switch(int_expr)
  • case int_const1 code1
  • break
  • case int_const2 code2
  • case int_const3 code3
  • break
  • default code4
  • Compact way of writing certain types of complex
    but common if()/else blocks.

(int_expr) must evaluate to an integer value at
runtime. (int_constN) must evaluate to a unique
integer constant at compile time. execution
jumps to case where (int_constN int_expr) is
TRUE. break terminates switch()
execution. default case Optional. Executes only
if NO other case executes.
9
Loop Structures
  • Special case of Selection Statement
  • One branch eventually leads back to the original
    selection statement.
  • Permits a block of code to be executed repeatedly
    as long as some test condition is satisfied.
  • C provides three different looping structures
  • while(), do/while(), for()
  • Only one is needed and any one is sufficient.
  • Different structures are better matches for
    different logic.
  • Using the proper one aides the programmer and
    anyone else reading the code.
  • The compiler doesnt care and will often
    implement the code identically regardless of
    which structure is used.

10
while() loop
  • Syntax
  • ini_code // not part of loop
  • while(test_expr)
  • loop_code
  • increment_code
  • next_code // not part of loop
  • Features
  • loop does not execute at all if test fails the
    first time.

11
do/while() loop
  • Syntax
  • ini_code // not part of loop
  • do
  • loop_code
  • increment_code
  • while(test_expr)
  • next_code // not part of loop
  • Features
  • loop will always execute at least once, even if
    test fails the first time.

12
for() loop
  • Syntax
  • for(ini_code test_expr inc_code)
  • loop_code
  • next_code // not part of loop
  • Features
  • Just a while() loop with the initialization and
    increment code formally incorporated into the
    syntax.
  • Can makes a cleaner divide between the loop logic
    and the housekeeping logic.
  • Makes it harder to leave omit initialization code
    if loop is moved or copied.
Write a Comment
User Comments (0)
About PowerShow.com