Summary

 < Day Day Up > 



All C++ programs require a main() function and a minimum, well-formed C++ program may have nothing but a main() function, although it wouldn’t be very useful. You can learn a lot about the language and the host computer by disassembling programs. The Metrowerks CodeWarrior disassembler can be configured to display output in several different formats.

Keywords are identifiers reserved for use by the compiler. You build C++ programs from declarations, statements, and expressions constructed from keywords, identifiers, fundamental data types, and operators.

C++ contains several fundamental data types such as char, int, float, and double, etc. Fundamental data types can represent a certain range of values depending on their size. Learn the size, in bytes, of data types by using the sizeof operator. Determine the range of data types by using the numeric_limits template class.

Numbers, characters, and strings of characters that appear directly in programs are known as literals. Integer literals can be expressed in decimal, octal, or hexadecimal format. Multiple character literals have a value equal to the integer value of their bit representation. Special characters can be represented by escape sequences. Floating point literals have type double unless specified as float with the f or F suffix. String literals are terminated with the null character ‘\0’. Boolean literals true and false represent the values 1 and 0.

Expressions, constructed from operators, specify a computation from which a value may result. Operators have precedence; use parenthesis to explicitly define operator precedence in an expression and make code easier to read and understand.

Identifiers are names given to objects in a program; adopt a naming convention and stick with it. A constant is an object whose value will remain unchanged during its lifetime. A constant must be defined at the point of declaration except in class member constants which require initialization in the class constructor. (see chapter 11)

A variable’s value will change during its lifetime. Variables have an area of authorized usage within a program known as scope. Redeclaring a variable in an enclosed scope can mask or hide a variable of the same name in outer or enclosing scopes. File scope variables have external linkage by default. Use the static keyword to limit file scope variable visibility to the file in which it is declared.

The main() function takes two forms. The cstdlib header defines the constants EXIT_SUCCESS and EXIT_FAILURE for use in the return statement or exit() function. Use atexit() function to call a function of your choosing upon exiting a program.

Stream input and output is provided by the cin and cout objects.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net