The C language provides several different kinds of constants: integer constants, such as 10
and 0x1C
; floating constants, such as 1.0
and 6.022e+23
; and character constants, such as 'a'
and '\x10'
. C also provides string literals, such as "hello, world"
and "\n"
. These may can all be referred to as literals.
Wiki Markup |
---|
When used in program logic, literals can reduce the readability of source code. As a result, literals, in general, and integer constants, in particular, are frequently called _magic numbers_ because their purpose is often obscured. Magic numbers maycan be constant values that represent either an arbitrary value (such as a determined appropriate buffer size) or a malleable concept (such as the age a person is considered an adult, which can change between geopolitical boundaries). Rather than embed literals in program logic, use appropriately named symbolic constants to clarify the intent of the code. In addition, if a specific value needs to be changed, reassigning a symbolic constant once is more efficient and less error prone than replacing every instance of the value \[[Saks 2002|AA. Bibliography#Saks 02]\]. |
...