- Shopping Bag ( 0 items )
Want a NOOK? Explore Now
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.
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.
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.
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. . . .
| 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 |
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.
Anonymous
Posted January 6, 2006
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 NoThank you for your feedback. Report this reviewThank you, this review has been flagged.Anonymous
Posted June 30, 2003
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 NoThank you for your feedback. Report this reviewThank you, this review has been flagged.Anonymous
Posted November 11, 2009
No text was provided for this review.
Overview