Digression - PowerPoint PPT Presentation

About This Presentation
Title:

Digression

Description:

Digression Symbolic Constants in C CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan and ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 7
Provided by: Hug76
Learn more at: http://web.cs.wpi.edu
Category:
Tags: digression

less

Transcript and Presenter's Notes

Title: Digression


1
Digression Symbolic Constants in C
  • CS-2303, System Programming Concepts
  • (Slides include materials from The C
    Programming Language, 2nd edition, by Kernighan
    and Ritchie and from C How to Program, 5th and
    6th editions, by Deitel and Deitel)

2
Specifying Symbolic Constants in C
  • Two ways
  • Textual substitution
  • Declaration of const data object

3
Constant Textual Substitution
  • See page
  • 14 89 in KR
  • 215 in DD
  • define NAME replacement-text
  • E.g.,
  • define PI 3.14159265358979323846
  • define LOWER 0define UPPER 300define STEP 20

It is traditional in C for textual substitution
names to be all UPPER CASE
4
Constant Textual Substitution
  • See page 14 89 in KR
  • define NAME replacement-text
  • E.g.,
  • define PI 3.14159265358979323846
  • define LOWER 0define UPPER 300define STEP 20

When a textual substitution constant is used in a
program, the compiler simply substitutes the
replacement text on the fly
5
Constant Declaration
  • const double pi 3.14159265358979323846
  • const double c 2.99792458e8 / speed of
    light in meters/sec /
  • Defines a value of the declared type with the
    declared name
  • I.e., creates storage to hold this value
  • Must be initialized
  • May never be left side of an assignment

6
Questions?
  • Next Topic
Write a Comment
User Comments (0)
About PowerShow.com