Docsity

Structured Programming in C - Lecture Slides | CPSC 206, Study notes of Computer Science

Toggle sidebar
bg1
Structured Programming in C 1
10/25/2007
Ward 1
Ronnie Ward
Exam 2 REVIEW
C by Dissection by Kelly/Pohl
Class WEB SITE:
http://courses.cs.tamu.edu/ward/206.f07/
CPSC 206: Structured
Programming in C
10/25/2007
Ward 2
Chapter 1 Summary
• Algorithms, procedures
• C program structure
• preprocessor directives
#define identifier rep_string
#define identifier
#include <stdio.h>
• main() function
• declarations
• statements
• printf & scanf
(control string, arguments)
• Constants, variables
• Function calls
• Operators: = + - * / %
• Expressions
• while (expression true)
statement
• Development process
• Development environments
– UNIX and PC
10/25/2007
Ward 3
Chapter 2 Summary
• Tokens and separators
• Comments /* … */
• Reserved tokens
• Identifiers
• Constants (so far)
– integer, float, double,
character and string
• Operators
– Precedence
– Associativity
– Binary, unary, pre/post
fix
• Standard library
functions (p. 545)
#include <stdlib.h>
– Eg. rand()
10/25/2007
Ward 4
Chapter 3 Summary
• Define true and false
– true (not 0) and false (0)
• operators yielding 0 or 1
– true (1) and false (0)
– relational < > <= >=
– equality == !=
– logical ! && ||
• negation (!) is unary
– value is 0 or 1
– !!val is usually not val
• Compound statement {…}
• if and if-else statements
• conditional operator ?:
• Loop control statements
– for, while, do-while
• break, continue and return
– Unconditional transfer of
control
• Avoid goto statement
• switch statement—later
pf3

Partial preview of the text

Download Structured Programming in C - Lecture Slides | CPSC 206 and more Study notes Computer Science in PDF only on Docsity!

10/25/ Ward 1

Ronnie Ward

Exam 2 REVIEW

C by Dissection by Kelly/Pohl

Class WEB SITE:

http://courses.cs.tamu.edu/ward/206.f07/

CPSC 206: Structured

Programming in C

10/25/ Ward 2

Chapter 1 Summary

  • Algorithms, procedures
  • C program structure
  • preprocessor directives #define identifier rep_string #define identifier #include <stdio.h>
  • main() function
    • declarations
    • statements
  • printf & scanf (control string, arguments) - Constants, variables - Function calls - Operators: = + - * / % - Expressions - while (expression true) statement - Development process - Development environments - UNIX and PC

10/25/ Ward 3

Chapter 2 Summary

  • Tokens and separators
  • Comments /* … */
  • Reserved tokens
  • Identifiers
  • Constants (so far)
    • integer, float, double, character and string - Operators - Precedence - Associativity - Binary, unary, pre/post fix - Standard library

functions (p. 545)

#include <stdlib.h>

  • Eg. rand() 10/25/ Ward 4

Chapter 3 Summary

  • Define true and false
    • true (not 0) and false (0)
  • operators yielding 0 or 1
    • true (1) and false (0)
    • relational < > <= >=
    • equality == !=
    • logical! && ||
  • negation (!) is unary
    • value is 0 or 1
    • !!val is usually not val
      • Compound statement {…}
      • if and if-else statements
      • conditional operator ?:
      • Loop control statements
        • for, while, do-while
      • break, continue and return
        • Unconditional transfer of control
      • Avoid goto statement
      • switch statement—later

10/25/ Ward 5

Chapter 4 Summary

  • Structured programming
    • “goto-less” code
    • Tops Down Development
    • Stepwise refinement
    • Program correctness
  • Use C functions for structuring large programs - function prototypes - type fname(parameter type list); - Function definition - Function call - Argument list - Program control - return statement - exit() function - Parameter passing - Call by value - Call by reference - assert macro example (^) 10/25/ Ward 6

Chapter 5 Summary

  • char type is stored in one

byte and is a small integer

  • Typically uses ASCII

encoding

  • Non-printing characters

such as ‘\n’—newline

  • getchar() and putchar()

macros

  • #include <stdio.h>
    • EOF character (-1) get data while( !end of file) { process data get more data }
    • #include <ctype.h>
      • char macros and functions
      • isalpha(c), or isupper(c)
      • toupper(c), or tolower(c)

10/25/ Ward 7

Chapter 6 Summary

  • C data types
    • Integral and floating
    • Built-in types
  • type determines:
    • Amount of memory
    • Data representation
    • Processor instructions
  • sizeof operator
    • sizeof int sizeof expr
      • type of constants
        • Integer, Float, Unsigned
      • type of variables and expressions
      • Automatic type conversion
      • Explicit type cast
      • Math library functions
        • #include <math.h>
        • sin(), cos(), tan(), pow() 10/25/ Ward 8

Chapter 7 Summary

• Enumeration types

• Keyword enum

• User-defined types

• Keyword typedef

• Enumerators

• Multi-file projects