music
OSdata.com: programming text book 

OSdata.com

constants

summary

    Representing constants in a computer.

free computer programming text book project

table of contents
If you like the idea of this project,
then please donate some money.
more information on donating

Google

stub section

    This subchapter is a stub section. It will be filled in with instructional material later. For now it serves the purpose of a place holder for the order of instruction.

    Professors are invited to give feedback on both the proposed contents and the propsed order of this text book. Send commentary to Milo, PO Box 1361, Tustin, California, 92781, USA.

constants

    Representing constants in a computer.

    Constants are named by a valid identifier.

    Quick summary of the rules for building valid constant identifiers in several major languages, using regular expressions:

Ada[a-zA-Z](_?[a-zA-Z0-9])*
ALGOL-68[a-z][a-z0-9 ]*
Awk[_a-zA-Z][_a-zA-Z0-9]*
B[_a-zA-Z][_a-zA-Z0-9]*
BourneShell[_a-zA-Z0-9]+
C[_a-zA-Z][_a-zA-Z0-9]*
C#[_a-zA-Z][_a-zA-Z0-9]*
C++[_a-zA-Z][_a-zA-Z0-9]*
COBOL[a-zA-Z][a-zA-Z0-9-]*
30 character maximum
Classic REXX[a-zA-Z!?@#][a-zA-Z0-9!?@#]*
Common Lispanything without a space and is not a number
E[_a-zA-Z][_a-zA-Z0-9]*
Eiffel[a-zA-Z][_a-zA-Z0-9]*
F#[_a-zA-Z][_a-zA-Z0-9']*
FORTRAN[A-Z][A-Z0-9]*
maximum of six characters
Forthanything without a space and is not a number
GNU-bc[a-z][a-z0-9_]*
Haskell[_A-Z][_a-zA-Z0-9']*
Java[_a-zA-Z$][_a-zA-Z0-9$]*
JavaScript[_a-zA-Z$][_a-zA-Z0-9$]*
Lispanything without a space and is not a number
Maple[_a-zA-Z][_a-zA-Z0-9]*
Mathematica[a-zA-Z][a-zA-Z0-9]*
Matlab[a-zA-Z][_a-zA-Z0-9]*
Mercury[_a-z][_a-zA-Z0-9']*
merd[_a-z][_a-zA-Z0-9]*[!?']*
Modula-3[a-zA-Z][_a-zA-Z0-9]*
MUMPS[a-zA-Z%][a-zA-Z0-9]*
OCaml[_A-Z][_a-zA-Z0-9']*
Pascal[a-zA-Z][a-zA-Z0-9]*
Perl[_a-zA-Z0-9]+
Perl6[_a-zA-Z0-9]+
PHP[_a-zA-Z][_a-zA-Z0-9]*
PL/I[a-zA-Z][a-zA-Z0-9]*
Pliant[_a-zA-Z][_a-zA-Z0-9]* or '[^']*'
Prolog[_A-Z][_a-zA-Z0-9]*
Python[_a-zA-Z][_a-zA-Z0-9]*
Rebol[_a-zA-Z?!.'+*&|=~-][_a-zA-Z0-9?!.'+*&|=~-]*
or
[^0-9[](){}":;/][^ \n\t[](){}":;/]*
Ruby[A-Z][_a-zA-Z0-9]*
Scheme[_a-zA-Z!0&*/:<=>?^][_a-zA-Z!0&*/:<=>?^0-9.+-]*
SmallTalk[a-zA-Z][a-zA-Z0-9]*
SML[_a-z][_a-zA-Z0-9']*
Tcl[_a-zA-Z][_a-zA-Z0-9]*

C

Stanford C essentials

    Stanford CS Education Library This [the following section until marked as end of Stanford University items] is document #101, Essential C, in the Stanford CS Education Library. This and other educational materials are available for free at http://cslibrary.stanford.edu/. This article is free to be used, reproduced, excerpted, retransmitted, or sold so long as this notice is clearly reproduced at its beginning. Copyright 1996-2003, Nick Parlante, nick.parlante@cs.stanford.edu.

char Constants

    A char constant is written with single quotes (') like 'A' or 'z'. The char constant 'A' is really just a synonym for the ordinary integer value 65 which is the ASCII value for uppercase 'A'. There are special case char constants, such as '\t' for tab, for characters which are not convenient to type on a keyboard.

'A'  uppercase 'A' character
'\n'  newline character
'\t'  tab character
'\0'  the “null” character -- integer value 0 (different from the char digit '0')
'\012'  the character with value 12 in octal, which is decimal 10

int Constants

    Numbers in the source code such as 234 default to type int. They may be followed by an ‘L’ (upper or lower case) to designate that the constant should be a long such as 42L. An integer constant can be written with a leading 0x to indicate that it is expressed in hexadecimal -- 0x10 is way of expressing the number 16. Similarly, a constant may be written in octal by preceding it with “0” -- 012 is a way of expressing the number 10.

Floating point Constants

    Constants in the source code such as 3.14 default to type double unless the are suffixed with an ‘f’ (float) or ‘l’ (long double). Single precision equates to about 6 digits of precision and double is about 15 digits of precision. Most C programs use double for their computations. The main reason to use float is to save memory if many numbers need to be stored. The main thing to remember about floating point numbers is that they are inexact. For example, what is the value of the following double expression?

    (1.0/3.0 + 1.0/3.0 + 1.0/3.0)    // is this equal to 1.0 exactly?

    The sum may or may not be 1.0 exactly, and it may vary from one type of machine to another. For this reason, you should never compare floating numbers to each other for equality (==) -- use inequality (<) comparisons instead. Realize that a correct C program run on different computers may produce slightly different outputs in the rightmost digits of its floating point computations.

    Stanford CS Education Library This [the above section] is document #101, Essential C, in the Stanford CS Education Library. This and other educational materials are available for free at http://cslibrary.stanford.edu/. This article is free to be used, reproduced, excerpted, retransmitted, or sold so long as this notice is clearly reproduced at its beginning. Copyright 1996-2003, Nick Parlante, nick.parlante@cs.stanford.edu.

end of Stanford C essentials

Ruby

    Constants in Ruby are identified by an initial capital letter. (such as Constantdata). It is conventional (although not required) to write constants in all capitals (such as CONSTANTDATA).

    Unlike most programming languages, it is possible to reassign a new value to a constant.

    Because consatnts are objects in Ruby, it is possible for the underlying constant to change value without warning.

other

   “1. One man’s constant is another man’s variable.” —Alan Perlis, Epigrams on Programming, ACM’s SIGPLAN Notices Volume 17, No. 9, September 1982, pages 7-13


free music player coding example

    Coding example: I am making heavily documented and explained open source code for a method to play music for free — almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).

    View music player in action: www.musicinpublic.com/.

    Create your own copy from the original source code/ (presented for learning programming).


return to table of contents
free downloadable college text book

view text book
HTML file

Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.

previous page next page
previous page next page

free computer programming text book project

Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

If you like the idea of this project,
then please donate some money.

send donations to:
Milo
PO Box 1361
Tustin, California 92781

Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

more information on donating

Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.


Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2010 Milo

    Created: October 31, 2010

    Last Updated: March 17, 2011


return to table of contents
free downloadable college text book

previous page next page
previous page next page