Skip to Main Content
C Programming: Visual Quickstart Guide
book

C Programming: Visual Quickstart Guide

by Larry Ullman, Marc Liyanage
October 2004
Beginner content levelBeginner
408 pages
9h 24m
English
Peachpit Press
Content preview from C Programming: Visual Quickstart Guide

Using Constants

One of the classic tips for creating readable code is to avoid the use of magic tokens: literal values (such as a number) that are generally meaningless without some context. Here is an example of bad programming form:

if (num < 90) {
   // Do this.
}

Although you probably knew why num had to be less than 90 when you wrote the application, that's exactly the kind of thing you'll forget when revisiting the code some time later. Moreover, there's little chance of another programmer comprehending the meaning of that number.

A constant is a macro that defines a literal value. You can then use the constant whenever you would otherwise use the value. By using constants instead of literal values, you ensure that you or anyone else who ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming

Intermediate C Programming

Yung-Hsiang Lu
Data Structures Using C

Data Structures Using C

Samir Kumar Bandyopadhyay, Kashi Nath Dey

Publisher Resources

ISBN: 0321287630Purchase book