Thread: Symbolic Constants??

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    13

    Symbolic Constants??

    Im confused at Symbolic Constants, I understand that they are a vlaue that cannot be changed and they are represented by a name.

    I just dont understand. ANYONE?
    ACAC
    http://www.t-p-n.co.uk//
    check it out

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    11

    Post

    Symbolic constants are used to make code clearer. Also, they make it easier to change the code. Example:

    #define STATE_TAX 8.05

    now, in your code, whenever the compiler sees the word STATE_TAX, it will replace STATE_TAX with 8.05

    you write: total = cost * STATE_TAX
    the compiler sees: total = cost * 8.05

    so as you can see, symbolic constants make the code clearer, because if you scan the line you can immediately understand it, whereas if you just saw 8.05, you'd say 'what the heck is 8.05?'

    Now, suppose the state tax decreases (fat chance, but let's suppose). If you hard-code 8.05, you will have to search out and replace every instance of 8.05 with, say, 7.95. But, if you have used the symbolic constant, all you must do is:

    #define STATE_TAX 7.95 (and recompile)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. is there a weird rule about symbolic constants?
    By i_can_do_this in forum C Programming
    Replies: 5
    Last Post: 07-10-2006, 07:14 AM
  3. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  4. Help with Constants and enum constants. Newbie learning C++.
    By UnregJDiPerla in forum C++ Programming
    Replies: 5
    Last Post: 01-07-2003, 08:29 PM
  5. anyone ever heard of symbolic programming
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-18-2002, 12:30 PM