C++: The Complete Reference [NOOK Book]

Overview

Best-selling genius Herb Schildt covers everything from keywords, syntax, and libraries, to advanced features such as overloading, inheritance, virtual functions, namespaces, templates, and RTTI—plus, a complete description of the Standard Template Library (STL).
Read More Show Less
... See more details below
C++: The Complete Reference

Available on NOOK devices and apps  
  • Nook Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK Study
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$52.99
BN.com price

Overview

Best-selling genius Herb Schildt covers everything from keywords, syntax, and libraries, to advanced features such as overloading, inheritance, virtual functions, namespaces, templates, and RTTI—plus, a complete description of the Standard Template Library (STL).
Read More Show Less

Editorial Reviews

Booknews
A guide to C++ by one of the standard authors. Covers features common to C & C++ features, specific C++ features, and software development (with concrete examples). Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780071502399
  • Publisher: McGraw-Hill Companies,Inc.
  • Publication date: 11/19/2002
  • Series: Osborne Complete Reference Series
  • Sold by: Barnes & Noble
  • Format: eBook
  • Edition number: 4
  • Sales rank: 740,110
  • File size: 28 MB
  • Note: This product may take a few minutes to download.

Meet the Author


Herbert Schildt is a leading authority on C and C++ and is a member of the ANSI/ISO C++ Standardization Committee. He has written numerous best-sellers, including C++ from the Ground Up, Expert C++, Teach Yourself C++, and many others.
Read More Show Less

Read an Excerpt


Chapter 2: EXPRESSIONS

This chapter examines the most fundamental element of the C (as well as the C++) language: the expression. As you will see, expressions in C/C++ are substantially more general and more powerful than in most other computer languages. Expressions are formed from these atomic elements: data and operators. Data may be represented either by variables or by constants. Like most other computer languages, C/C++ supports a number of different types of data. It also provides a wide variety of operators.

The Five Basic Data Types

There are five atomic data types in C: character, integer, floating-point, and valueless (char, int, float, double, and void, respectively). As you will see, all other data types in C are based upon one of these types. The size and range of these data types may vary between processor types and compilers. However, in all cases a character is 1 byte. The size of an integer is usually the same as the word length of the execution environment of the program. For most 16-bit environments, such as DOS or Windows 3.1, an integer is 16 bits. For most 32-bit environments, such as Windows NT, an integer is 32 bits. However, you cannot make assumptions about the size of an integer if you want your programs to be portable to the widest range of environments. It is important to understand that both C and C++ only stipulate the minimal range of each data type, not its size in bytes.

NOTE: To the five basic data types defined by C, C++ adds two more. bool and wchar_t. These are discussed in Part Two.

implemented. Integers will generally correspond to the natural size of a word on the host computer. Values of type char are generally used to hold values defined by the ASCII character set. Values outside that range may be handled differently by different compilers.

the floating- point numbers. Whatever the method, the range is quite large. Standard C specifies that the minimum range for a floating-point value is 1E-37 to 1E+37. The minimum number of digits of precision for each floating-point type is shown in Table 2-1.

NOTE: Standard C++ does not specify a minimum size or range for the basic types. Instead, it simply states that they must meet certain requirements. For example, Standard C++ states that an int will "have the natural size suggested by the architecture of the execution environment." In all cases, this will meet or exceed the minimum ranges specified by Standard C. Each C++ compiler specifies the size and range of the basic types in the header <climits>. preceding them. situation more precisely. The list of modifiers is shown here:

base types. You can apply unsigned and signed to characters. You may also apply long to double. Table 2-1 shows all valid data type combinations, along with their minimal ranges and approximate bit widths. (These values also apply to a typical C++ implementation.) Remember, the table shows the minimum range that these types win have as specified by Standard C/C++, not their typical range. For example, on computers that use two's complement arithmetic (which is nearly all), an integer will have a range of at least 32,767 to -32,768.

integer declaration assumes a signed number. The most important use of signed is to modify char in implementations in which char is unsigned by default.

highorder bit of the integer is interpreted. If you specify a signed integer, the compiler generates code that assumes that the high-order bit of an integer is to be used as a sign flag. If the sign flag is 0, the number is positive; if it is 1, the number is negative.

approach, which reverses all bits in the number (except the sign flag), adds 1 to this number, and sets the sign flag to 1.

have half the absolute magnitude of their unsigned relatives. For example, here is 32,767:

If the high-order bit were set to 1, the number would be interpreted as However, if you declare this to be an unsigned int, the number becomes 65,535 when the high order bit is set to 1.

Identifier Names

In C/C++, the names of variables, functions, labels, and various other user-defined objects are called identifiers. These identifiers can vary from one to several characters. The first character must be a letter or an underscore, and subsequent characters must be either letters, digits, or underscores. Here are some correct and incorrect identifier names:

Correct Incorrect
Count 1 count
test23 hi! there

high_balance high balance

necessarily be significant. If the identifier will be involved in an external fink process, then at least the first six characters will be significant. These identifiers, called external names, include function names and global variables that are shared between files. If the identifier is not used in an external link process, then at least the first 31 characters will be significant. This type of identifier is called an internal name and includes the names of local variables, for example. In C++, there is no limit to the length of an identifier, and at least the first 1,024 characters are significant. This difference may be important if you are converting a program from C to C++.

count, Count, and COUNT are three separate identifiers.

the same name as functions that are in the C or C++ library.

Variables

As you probably know, a variable is a named location in memory that is used to hold a value that may be modified by the program. All variables must be declared before they can be used. The general form of a declaration is

type variable_list;

Here, type must be a valid data type plus any modifiers, and variable_list may consist of one or more identifier names separated by commas. Here are some declarations:

int i, j,1;

short int si;

unsigned int ui;

double balance, profit, loss;

Remember, in C/C++ the name of a variable has nothing to do with its type.

Where Variables Are Declared

Variables will be declared in three basic places: inside functions, in the definition of function parameters, and outside of all functions. These are local variables, formal parameters, and global variables.

Local Variables

some C/C++ book uses the more common term, local variable. Local variables may be referenced only by statements that are inside the block in which the variables are declared. In other words, local variables are not known outside their own code block. Remember, a block of code begins with an opening curly brace and terminates with a dosing curly brace.

declared is executing. That is, a local variable is created upon entry into its block and destroyed upon exit.

function. For example, consider, the following two functions:

void func1(void) {
int x;

}

void func2(void)
{

int x;

X = -199;

}

The integer variable x is declared twice, once in func1( ) and once in func2( ). The x in func1( ) has no bearing on or relationship to the x in func2( ). This is because each x is only known to the code within the same block as the variable declaration.

local variables. However, since all nonglobal variables are, by default, assumed to be auto, this keyword is virtually never used. Hence, the examples in this book will not use it. (It has been said that auto was included in C to provide for source-level compatibility with its predecessor B. Further, auto is supported in C++ to provide compatibility with C.)

variables used by a function immediately after the function's opening curly brace and before any other statements. However, you may declare local variables within any code block. The block defined by a function is simply a special case. For example,

void f (void)
{
int t;
scanf ( "%d%*c",&t);

if( t-=1) {

}

}

Here, the local variable s is created upon entry into the if code block and destroyed upon exit. Furthermore, s is known only within the if block and may not be referenced elsewhere even in other parts of the function that contains it.

that memory for the variable will only be allocated if needed. This is because local variables do not come into existence until the block in which they are declared is entered. You might need to worry about this when producing code for dedicated controllers (like a garage door opener that responds to a digital security code) in which RAM is in short supply, for example.

prevent unwanted side effects. Since the variable does not exist outside the block in which it is declared, it cannot be accidentally altered.

declare local variables. In C, you must declare all local variables at the start of the block in which they are defined, prior to any "action" statements. For example, the following function is in error if compiled by a C compiler.

/* This function is in error if compiled as a C program, but perfectly acceptable if compiled as a C++ program.
*/
void f(void)
{
j = 20;
}

However, in C++, this function is perfectly valid because you can define local variables at any point in your program. (The topic of C++ variable declaration is discussed in depth in Part Two.)

from the block in which they are declared, their content is lost once the block is left. This is especially important to remember when calling a function. When a function is called, its local variables are created, and upon its return they are destroyed. This means that local variables cannot retain their values between calls. (However, you can direct the compiler to retain their values by using the static modifier.)

fact that the stack is a dynamic and changing region of memory explains why local variables cannot, in general, hold their values between function calls. . . .

Read More Show Less

Table of Contents

1 An Overview of C 3
2 Expressions 13
3 Statements 57
4 Arrays and Strings 89
5 Pointers 111
6 Functions 135
7 Structures, Unions, Enumerations, and User-Defined Types 161
8 Console I/O 185
9 File I/O 207
10 The Preprocessor and Comments 231
11 An Overview of C++ 249
12 Classes and Objects 277
13 Arrays, Pointers, and References 313
14 Function and Operator Overloading 343
15 Inheritance 383
16 Virtual Functions and Polymorphism 409
17 The C++ I/O System Basics 423
18 C++ File I/O 457
19 Array-Based I/O 485
20 Templates 499
21 Exception Handling 519
22 Miscellaneous Issues and Advanced Topics 535
23 A String Class 563
24 A Pop-up Window Class 591
25 A Generic Linked List Class 625
A The Proposed Standard Class Libraries 655
Read More Show Less

Preface

This is the third edition of C++: The Complete Reference. In the years that have transpired since the second edition, C++ has undergone many changes. Perhaps the most important is that it is now a standardized language. In November of 1997, the ANSI/ISO committee charged with the task of standardizing C++, passed out of committee an international Standard for C++. This event marked the end of a very long, and at times contentious, process. As a member of the ANSI/ISO C++ committee, I watched the progress of the emerging standard, following each debate and argument. Near the end, there was a world-wide, daily dialogue, conducted via e- mail, in which the pros and cons of this or that issue were put forth, and finally resolved. While the process was longer and more exhausting than anyone at first envisioned, the result was worth the trouble. We now have a standard for what is, without question, the most important programming language in the world.

During standardization, several new features were added to C++. Some are relatively small. Others, like the STL (Standard Template Library) have ramifications that will affect the course of programming for years to come. The net effect of the additions was that the scope and range of the language were greatly expanded. For example, because of the addition of the numerics library, C++ can be more conveniently used for numeric processing. Of course, the information contained in this edition reflects the International Standard for C++ defined by the ANSI/ISO committee, including its new features.

Read More Show Less

Customer Reviews

Average Rating 3.5
( 3 )
Rating Distribution

5 Star

(2)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(1)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 3 Customer Reviews
  • Anonymous

    Posted January 6, 2006

    Excellent book!

    Pros : The book was an excellent resource to go to if I ever needed any help with anything over C++. I strongly suggest this book to anyone who wants to learn C++ or who is an advanced programmer that needs a reference book to look up something that they might get confused about. I was trying to learn C++ for a few months going online and reading sources off the Internet, but I could never really quite understand the language itself. Whenever I got the book it has turned into a great source for pretty much all of my C++ questions and has helped me out a lot with examples and in depth explanations over different objects in C++. I was actually trying to learn C++ on my own since it was the cheapest at the time and I had tons of spare time to read the book and go in depth in the language. A few other things about the book are * Figuring out the differences between C and C++ * Excellent examples over the information Schildt (the author) was teaching about * Great resource for the advanced programmers and a great guide to start off beginner programs in C/C++ Must I say anymore about this excellent book!?!??!?! If you are interested in programming with C++, this is a must have book! Cons : The only thing I disliked about the book was that I didn't quite understand the examples in the book when I was first starting. I of course didn't know a whole lot about C++, let alone C when I first got this book. Aaron

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 30, 2003

    Complete!

    I had learned the basics of the c++ language, classes, functions, variables, pointers, but I hadn't had anything to reinforce my knowledge. I also didn't have a knowledgable understanding of the difference between C++ and C. Where was the line? I read C++: The Complete Reference Straight Through and my questions were answered. It doesn't cover windows programming, but it covers every aspect of the C++ language. It also gave me a wonderful understanding of using the Standard Template Library and especially the string class. After reading this, I've found that I'm ready to begin in any C++ subject from windows programming to CGI scripting.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 11, 2009

    No text was provided for this review.

Sort by: Showing all of 3 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)