C: The Complete Reference / Edition 4 available in Paperback
- ISBN-10:
- 0072121246
- ISBN-13:
- 9780072121247
- Pub. Date:
- 04/26/2000
- Publisher:
- McGraw Hill LLC
- ISBN-10:
- 0072121246
- ISBN-13:
- 9780072121247
- Pub. Date:
- 04/26/2000
- Publisher:
- McGraw Hill LLC
Buy New
$61.00Buy Used
$21.48-
PICK UP IN STORE
Your local store may have stock of this item.
Available within 2 business hours
$21.48-
SHIP THIS ITEM
Temporarily Out of Stock Online
Please check back later for updated availability.
Overview
Whether you are a beginning C programmer or a seasoned pro, the answers to all your C questions can be found in this one-stop resource
Another gem from Herb Schildtbest-selling programming author with more than 2.5 million books sold! C: The Complete Reference, Fourth Edition gives you full details on C99, the New ANSI/ISO Standard for C. You'll get in-depth coverage of the C language and function libraries as well as all the newest C features, including restricted pointers, inline functions, variable-length arrays, and complex math. This jam-packed resource includes hundreds of examples and sample applications.
Product Details
ISBN-13: | 9780072121247 |
---|---|
Publisher: | McGraw Hill LLC |
Publication date: | 04/26/2000 |
Series: | Osborne Complete Reference Series |
Edition description: | List |
Pages: | 805 |
Product dimensions: | 7.50(w) x 9.20(h) x 1.90(d) |
About the Author
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 istype 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. . . .
Table of Contents
Part I: The Foundtion of C++: The C Subset.An Overview of C.
Expressions.
Statements.
Arrays and Null-Terminated Strings.
Pointers.
Functions.
Structures, Unions, Enumerations, and User-Defined Types.
C-Style Console I/O.
File I/O.
The Preprocessor and Comments.
Part II: C++.
The Integrated Services Digital Network (ISDN).
Frame Relay and Asynchronous Transfer Mode.
Wireless Communications.
Voice Processing Systems.
Modems, Facsimiles and Fax-on-Demand.
Videoconferencing.
Computer Telephony Integration.
CATV and Telephony.
Vendors. C++ File I/O.
Run-Time Type ID and the Casting Operators.
Namespaces, Conversion Functions, and Other Advanced Topics.
Introducting the Standard Template Library.
Part III: The Standard Function Library.
The C-Based I/O Functions.
The String and Character Functions.
The Mathematical Functions.
Time, Date, and Localization Functions.
The Dynamic Allocation Functions.
Utility Functions.
The Wide-Character Functions.
(and more...)
Preface
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.