... functions
you use from the library (see Figure 1.4).
12 CPRIMER PLUS
FIGURE 1.4
Compiler and linker.
concrete .c
concrete.obj
concrete.exe
source code
Compiler
object code
library code
executable ... 1.5
Preparing a C program
using Unix.
name .c
a.out
source code
enter
source code
Compiler
executable code
run program by
typing filename
a.out
Text Editor
What about the object code? The cc compiler creates ... Some compilers provide an option
to create an executable named concrete.com instead. In either case, you can run the program
by typing the basename at the command line:
C& gt;concrete
C on the Macintosh
The...
... Windows compiler. You
start by selecting File, New Project. You are then given a choice of project types. For
CodeWarrior, choose MacOS :C/ C++:ANSI C+ + Console in older versions, or
MacOS :C/ C++:Standard ... Console:Std C+ + Console in mid-vintage versions, or MacOS C+ +
Stationery:Mac OS Carbon:Standard Console :C+ + Console Carbon. (You can make other valid
choices; for example, you might opt for Classic ... Classic instead of Carbon or C+ + Console Carbon
Altivec instead of plain C+ + Console Carbon.)
CodeWarrior supplies a small source code file as part of the initial project. You can try compil-
ing...
... For example, compiling and linking a source code file called
concrete .c produces a file called concrete.exe. Some compilers provide an option to create an
executable named concrete.com instead. ... either case, you can run the program by typing the
basename at the command line:
C& gt;concrete
C on the Macintosh
The best known Macintosh C/ C++ compiler is the Metrowerks CodeWarrior compiler. ...
provided by GNU. The compile command would look like this:
8 CPrimerPlus 5th Edition
8
Recall that the compiler is a program whose job is to convert source code into executable code.
Executable...
... might use
non -C features, such as namespace
std
ptg7068951
19
The Mechanics of Creating a Program
executable code
source code
COMPILER
object code
LINKER
startup code
library code
Figure 1.3 ... including New C Primer
Plus, which received the Computer Press Association’s 1990 Best How-to Computer
Book Award, and C+ + Primer Plus, nominated for the Computer Press Association’s Best
How-to Computer ... programs
C old style Ends in .h math.h Usable byC and C+ + programs
C+ + new style No extension iostream Usable by C+ + programs, uses
namespace std
Converted Cc prefix, no
extension
cmath Usable by C+ +...
... Fourth Edition of C+ + Primer
Plus reflects the ISO/ANSI standard and describes this matured version of C+ +.
C+ + PrimerPlus integrates discussing the basic C language with presenting C+ + features, ... you'll meet the cctype library of functions for evaluating character relations, such as testing
whether a character is a digit or a nonprinting character.
Chapter 7: Functions ?C+ +'s Programming ... base class code. This chapter
discusses public inheritance, which models is-a relationships, meaning that a derived object is a
special case of a base object. For example, a physicist is a special...
... between
C and C+ + programs.
Table 1.1. Source Code Extensions
C+ + Implementation Source Code Extension
UNIX AT&T C, cc, cxx, c
GNU C+ + C, cc, cxx, cpp
Symantec cpp, cp
Borland C+ +
cpp
Watcom
cpp
Microsoft ... implemented C+ + with a C+ +-to -C compiler program instead of
developing a direct C+ +-to-object code compiler. This program, called cfront (for C
front end), translated C+ + source code to C source code, ... the CC command to compile your program. The name is in uppercase letters to
distinguish it from the standard UNIX C compiler cc. The CC compiler is a
command-line compiler, meaning you type compilation...
... while.
C- Style Comments
C+ + also recognizes C comments, which are enclosed
between /* and */ symbols:
#include <iostream> /* a C- style comment */
Because the C- style comment is terminated by ... general, a C+ + function is activated, or called, by another function, and the function
heading describes the interface between a function and the function that calls it. The part
preceding the function ... a
namespace so that you can use the name of a namespace to indicate which vendor's
product you want. So Microflop Industries could place its definitions in a namespace called
Microflop. Then Microflop::wanda()...
... the C+ + class corresponds to what some languages term an object type, and the C+ +
object corresponds to an object instance or instance variable.
Now get a little more specific. Recall this declaration ... number; that is, a 3
character and an 8 character. The program internally stores the code for the 3 character
and the 8 character. To print the string, cout simply prints each character in the string. ... function call, the invoked function is termed the called function, and the
function containing the function call is termed the calling function. (See Figure 2.6.)
Figure 2.6. Calling a function.
The...
... or exceed the number of distinct
characters. In the U.S., the basic character sets usually are the ASCII
and EBCDIC sets, each of which can be accommodated by 8 bits, so
the C+ + byte typically ... object is an entity created according to a class prescription, just as a simple
variable is an entity created according to a data type description.
C+ + provides two predefined objects (cin and cout) ... symbolic constants, too. (See
Listing 3.2.) However, the #define directive is a C relic. C+ + has a
better way for creating symbolic constants (the const keyword,
This document was created by an...
... to create a character constant and don't use single quotes when
including it as part of a string.
Table 3.2. C+ + Escape Sequence Codes
Character Name ASCII Symbol C+ + Code ASCII Decimal Code ... symbols, such as { and =, used in the C language, and a scattering of other
characters, such as newline and space. Then there is a basic execution character set (characters that
can be produced by the ... awkward conversion functions to convert
characters to ASCII and back.
Finally, the program uses the cout.put() function to display both c and a character constant.
A Member Function: cout.put()
Just...
... need
greater accuracy, use double or long double.
Which Order: Operator Precedence and Associativity
Can you trust C+ + to do complicated arithmetic? Yes, but you must know the rules C+ + uses. For
example, ... expectation. In this listing, for example, the char variable
ch holds the code for the letter Z. Using cout with ch displays the character Z, because cout zeros in
This document was created by ... you can use a type
cast to display the ASCII code for a type char value.
Listing 3.13 typecast.cpp
This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com...
... through
memory byte -by- byte, interpreting each byte as a character to print, until it reached a null
character. Because null characters, which really are bytes set to zero, tend to be common
in memory, ... role in C- style strings. For example, C+ + has many functions that handle
strings, including those used by cout. They all work by processing a string
character -by- character until they reach the ... this call separately:
cin >> year;
cin.get(); // or cin.get(ch);
Or, you can concatenate the call, making use of the fact that the expression cin >> year
returns the cin object:
(cin...
... string. By the way, because pal.name is a
character array, we can use subscripts to access individual characters in the array. For
This document was created by an unregistered ChmMagic, please ... where to place the structure declaration. There are two choices for
structur.cpp. You could place the declaration inside the main() function, just after the
opening brace. The second choice, and ... two
choices. But for programs consisting of two or more functions, the difference can be
crucial. The external declaration can be used by all the functions following it, whereas the
internal declaration...
... hold values. In this case, pointers become the only
access to that memory. In C, you could allocate memory with the library function malloc().
You still can do so in C+ +, but C+ + also has a better ... the second case,
you also can access the int by name: higgens. In the first case, your only access is via the
pointer. That raises a question: Because the memory to which pn points lacks a name,
what ... then continues printing characters until it runs into the null character (\0). In short, if
you give cout the address of a character, it prints everything from that character to the first
null character...