digression symbolic constants in c l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Digression – Symbolic Constants in C PowerPoint Presentation
Download Presentation
Digression – Symbolic Constants in C

Loading in 2 Seconds...

play fullscreen
1 / 6

Digression – Symbolic Constants in C - PowerPoint PPT Presentation


  • 317 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Digression – Symbolic Constants in C' - strom


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
digression symbolic constants in c

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)

Symbolic Constants in C

specifying symbolic constants in c
Specifying Symbolic Constants in C
  • Two ways
    • Textual substitution
    • Declaration of const data object

Symbolic Constants in C

constant textual substitution

A preprocessor directive!

Constant – Textual Substitution
  • See page
      • 14 & 89 in K&R
      • 215 in D&D

#define NAME replacement-text

  • E.g.,

#define PI 3.14159265358979323846

#define LOWER 0#define UPPER 300#define STEP 20

It is traditional in C for textual substitution names to be all UPPER CASE

Symbolic Constants in C

constant textual substitution4
Constant – Textual Substitution
  • See page 14 & 89 in K&R

#define NAME replacement-text

  • E.g.,

#define PI 3.14159265358979323846

#define LOWER 0#define UPPER 300#define STEP 20

When a textual substitution constant is used in a program, the compiler simply substitutes the replacement text on the fly

Symbolic Constants in C

constant declaration
Constant Declaration

const double pi = 3.14159265358979323846;

const double c = 2.99792458e+8; /* 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

Symbolic Constants in C

questions

Questions?

Next Topic

Symbolic Constants in C