100% found this document useful (3 votes)
69 views

C C programmer s reference 3rd ed Edition Schildt download pdf

ed

Uploaded by

osamadilag3a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
69 views

C C programmer s reference 3rd ed Edition Schildt download pdf

ed

Uploaded by

osamadilag3a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Visit https://ebookgate.

com to download the full version and


explore more ebooks

C C programmer s reference 3rd ed Edition Schildt

_____ Click the link below to download _____


https://ebookgate.com/product/c-c-programmer-s-
reference-3rd-ed-edition-schildt/

Explore and download more ebooks at ebookgate.com


Here are some recommended products that might interest you.
You can download now and explore!

Borland C Builder The Complete Reference Herbert Schildt

https://ebookgate.com/product/borland-c-builder-the-complete-
reference-herbert-schildt/

ebookgate.com

VBScript Programmer s Reference 3rd Edition Adrian


Kingsley-Hughes

https://ebookgate.com/product/vbscript-programmer-s-reference-3rd-
edition-adrian-kingsley-hughes/

ebookgate.com

Javascript programmer s reference 1st ed Edition Alexei


White

https://ebookgate.com/product/javascript-programmer-s-reference-1st-
ed-edition-alexei-white/

ebookgate.com

Beginning Visual C 2010 Wrox Programmer to Programmer 1st


Edition Karli Watson

https://ebookgate.com/product/beginning-visual-c-2010-wrox-programmer-
to-programmer-1st-edition-karli-watson/

ebookgate.com
HTML5 Programmer s Reference 1st Edition Jonathan Reid

https://ebookgate.com/product/html5-programmer-s-reference-1st-
edition-jonathan-reid/

ebookgate.com

Java A Beginner s Guide 3rd Edition Schildt

https://ebookgate.com/product/java-a-beginner-s-guide-3rd-edition-
schildt/

ebookgate.com

Professional C 4 and NET 4 Wrox Programmer to Programmer


1st Edition Christian Nagel

https://ebookgate.com/product/professional-c-4-and-net-4-wrox-
programmer-to-programmer-1st-edition-christian-nagel/

ebookgate.com

Martindale The complete drug reference 37th Edition Shawn


C. Sweetman (Ed.)

https://ebookgate.com/product/martindale-the-complete-drug-
reference-37th-edition-shawn-c-sweetman-ed/

ebookgate.com

The Fungi 3rd ed 2015 3rd Edition Sarah C. Watkinson

https://ebookgate.com/product/the-fungi-3rd-ed-2015-3rd-edition-sarah-
c-watkinson/

ebookgate.com
. .C/C++ Programmer's Reference, Third Edition
by Herbert Schildt ISBN:0072227222

McGraw-Hill/Osborne © 2003 (358 pages)

This guide reviews the rules and syntax of the principle commands that comprise C and its
object-oriented cousin, C++. The reference consists of 19 chapters that define operators and
the standard input/output, string, character, and more.

Table of Contents

C/C++ Programmer?s Reference, Third Edition


Introduction
Chapter 1 - Data Types, Variables, and Constants
Chapter 2 - Functions, Scopes, Namespaces, and Headers
Chapter 3 - Operators
Chapter 4 - The Preprocessor and Comments
Chapter 5 - Keyword Summary
Chapter 6 - The Standard C I/O Functions
Chapter 7 - The String and Character Functions
Chapter 8 - The C Mathematical Functions
Chapter 9 - The C++ Mathematical Functions
Chapter 10 - Time, Date, and Localization Functions
Chapter 11 - The Dynamic Allocation Functions
Chapter 12 - Miscellaneous Functions
Chapter 13 - The Wide-Character Functions
Chapter 14 - The Old-Style C++ I/O System
Chapter 15 - The ANSI/ISO Standard C++ I/O Classes
Chapter 16 - The C++ Standard Template Library
Chapter 17 - The C++ String, Exception, Complex, and Pair Classes
Chapter 18 - Library Features Added by C99
Chapter 19 - The .NET Managed Extensions to C++
Index
Back Cover
Legendary programming author Herbert Schildt distills and organizes the essential elements of C and C++ into a convenient
and easy-to-use format that gives you quick, accurate answers to your C/C++ programming questions. You’ll quickly locate
clear, concise explanations of the C and C++ programming syntax, keywords, operators, preprocessor directives, and
function and class libraries. This ready resource even describes the extended keywords used for .NET programming.
Whether you’re a beginner programmer or an experienced pro, this is one indispensable tool that you won’t want to be
without.

Quickly find the syntax for keywords, operators, functions, classes, and preprocessor directives
Fully covers the Standard Template Library (STL) and the I/O system
Packed with programming tips to speed your work
Solve problems in all C/C++ environments—including Visual C++

About the Author

Herbert Schildt, the world’s leading programming author, is an authority on the C, C++, Java, and C# programming
languages and a master Windows programmer. He was a member of the ANSI/ISO committees that standardized C and
C++.
C/C++ Programmer’s Reference, Third Edition
Herbert Schildt

McGraw-Hill/Osborne

New York Chicago San Francisco


Lisbon London Madrid Mexico City Milan
New Delhi San Juan Seoul Singapore Sydney Toronto

McGraw-Hill/Osborne
2600 Tenth Street
Berkeley, California 94710
U.S.A.

To arrange bulk purchase discounts for sales promotions, premiums, or fund-raisers, please contact
McGraw-Hill/Osborne at the above address. For information on translations or book distributors outside the U.S.A.,
please see the International Contact Information page immediately following the index of this book.

C/C++ Programmer’s Reference, Third Edition

Copyright © 2003 by The McGraw-Hill Companies. All rights reserved. Printed in the United States of America. Except
as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form
or by any means, or stored in a database or retrieval system, without the prior written permission of publisher, with the
exception that the program listings may be entered, stored, and executed in a computer system, but they may not be
reproduced for publication.

1234567890 DOC DOC 0198765432

ISBN 0-07-222722-2

Publisher: Brandon A. Nordin

Vice President & Associate Publisher: Scott Rogers

Acquisitions Editor: Lisa McClain

Project Editor: Laura Stone

Acquisitions Coordinator: Athena Honore

Technical Editor: Greg Guntle

Copy Editor: Dennis Weaver

Proofreaders: Linda Medoff, Paul Medoff

Indexer: Sheryl Schildt

Composition: Apollo Publishing Services, George Toma Charbak

Illustrators: Michael Mueller, Lyssa Wald

Series Design: Peter F. Hancik

This book was composed with Corel VENTURA™ Publisher.

Information has been obtained by McGraw-Hill/Osborne from sources believed to be reliable. However, because of the
possibility of human or mechanical error by our sources, McGraw-Hill/Osborne, or others, McGraw-Hill/Osborne does
not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or
omissions or the results obtained from the use of such information.
About the Author

Herbert Schildt is a leading authority on C and C++ and was a member of the ANSI/ISO committees that standardized
C and C++. His books have sold more than 3 million copies worldwide and have been translated into all major foreign
languages. He is the author of C: The Complete Reference, C++: The Complete Reference, C++: A Beginner’s Guide,
C++ from the Ground Up, and many other best-sellers, including C#: The Complete Reference and Java 2: The
Complete Reference. Schildt holds a Master’s degree in computer science from the University of Illinois.
Introduction
C and C++ are two of the world’s most important programming languages. Indeed, to be a professional programmer
today implies proficiency in these two languages. They are the foundation upon which modern programming is built.

C was invented by Dennis Ritchie in the 1970s. C is a middle-level language. It combines the control structures of a
high-level language with the ability to manipulate bits, bytes, and pointers (addresses). Thus, C gives the programmer
nearly complete control over the machine. C was first standardized late in 1989 when the American National
Standards Institute (ANSI) standard for C was adopted. This version of C is commonly referred to as C89. This
standard was also adopted by ISO (International Standards Organization). C89 was amended slightly in 1995.

C++ was created by Bjarne Stroustrup, beginning in 1979. The development and refinement of C++ was a major effort,
spanning the 1980s and most of the 1990s. Finally, in 1998 an ANSI/ISO standard for C++ was adopted. In general
terms, C++ is the object-oriented version of C. C++ is built upon the foundation of C89, including its 1995
amendments. In fact, the version of C defined by C89 is commonly referred to as the “C subset of C++.” Although C++
began as a set of object-oriented extensions to C, it soon expanded into being a programming language in its own
right. Today, C++ is nearly twice the size of the C language. Needless to say, C++ is one of the most powerful
computer languages ever devised.

In 1999, a new ANSI/ISO standard for C was adopted. This version is called C99. It includes a number of refinements
and several new features. Some of these ?new?features were borrowed from C++, but some are entirely new
innovations. Thus, several of the elements added by C99 are incompatible with C++. This means that with the advent
of C99, Standard C is no longer a pure subset of C++. Fortunately, many of the incompatibilities relate to special-use
features that are readily avoided. Thus, it is still easy to write code that is compatible with both C and C++. At the time
of this writing, no major compiler currently accepts all of the C99 additions.

The following table synopsizes the relationships between C89, C99, and C++.

C89 The original ANSI/ISO standard for C. C89 is what most programmers today think of as C.

C++ The object-oriented version of C. The current ANSI/ISO standard for C++ is built upon C89. Thus, C89
forms a subset of C++.

C99 The latest standard for C. Includes all of C89, but adds several new features. Some of the new
features are not supported by the current standard for C++.

The material in this book describes C89, C99, and C++. When a feature is unique to one of these, it will be so flagged.
Otherwise, you can assume that the feature applies to all three.

As you are undoubtedly aware, C and C++ are large topics. It is, of course, not possible to cover every aspect of these
important languages here. Instead, this quick reference distills their most salient features into a convenient and easy to
use form.
Chapter 1: Data Types, Variables, and Constants
C and C++ offer the programmer a rich assortment of built-in data types. Programmer-defined data types can be
created to fit virtually any need. Variables can be created for any valid data type. Also, it is possible to specify
constants of C/C++’s built-in types. In this section, various features relating to data types, variables, and constants are
discussed.

The Basic Types


C89 defines the following elemental data types:

Type Keyword

Character char

Integer int

Floating point float

Double floating point double

Valueless void

To these, C99 adds the following:

Type Keyword

Boolean (true/false) _Bool

Complex _Complex

Imaginary _Imaginary

C++ defines the following basic types:

Type Keyword

Boolean (true/false) bool

Character char

Integer int

Floating point float

Double floating point double

Valueless void

Wide character wchar_t

As you can see, all versions of C and C++ provide the following five basic types: char, int, float, double, and void.
Also notice that the keyword for the Boolean type is bool in C++ and _Bool in C99. No Boolean type is included in C89.

Several of the basic types can be modified using one or more of these type modifiers:

signed

unsigned
short

long

The type modifiers precede the type name that they modify. The basic arithmetic types, including modifiers, allowed by
C and C++ are shown in the following table along with their guaranteed minimum ranges. Most compilers will exceed
the minimums for one or more types. Also, if your computer uses two’s complement arithmetic (as most do), then the
smallest negative value that can be stored by a signed integer will be one more than the minimums shown. For
example, the range of an int for most computers is –32,768 to 32,767. Whether type char is signed or unsigned is
implementation dependent.

Type Minimum Range

char –127 to 127 or 0 to 255

unsigned char 0 to 255

signed char –127 to 127

int –32,767 to 32,767

unsigned int 0 to 65,535

signed int same as int

short int same as int

unsigned short int 0 to 65,535

signed short int same as short int

long int –2,147,483,647 to 2,147,483,647

signed long int same as long int

unsigned long int 0 to 4,294,967,295

long long int 63 63


–(2 –1) to 2 –1 (C99 only)

signed long long int same as long long int (C99 only)

unsigned long long int 64


0 to 2 –1 (C99 only)

float 6 digits of precision

double 10 digits of precision

long double 10 digits of precision

wchar_t same as unsigned int

When a type modifier is used by itself, int is assumed. For example, you can specify an unsigned integer by simply
using the keyword unsigned. Thus, these declarations are equivalent.
unsigned int i; // here, int is specified
unsigned i; // here, int is implied
Declaring Variables
All variables must be declared prior to use. Here is the general form of a declaration:

type variable_name;

For example, to declare x to be a float, y to be an integer, and ch to be a character, you would write
float x;
int y;
char ch;

You can declare more than one variable of a type by using a comma-separated list. For example, the following
statement declares three integers:
int a, b, c;

Initializing Variables

A variable can be initialized by following its name with an equal sign and an initial value. For example, this declaration
assigns count an initial value of 100:
int count = 100;

An initializer can be any expression that is valid when the variable is declared. This includes other variables and
function calls. However, in C, global variables and static local variables must be initialized using only constant
expressions.
Identifiers
Variable, function, and user-defined type names are all examples of identifiers. In C/C++, identifiers are sequences of
letters, digits, and underscores from one to several characters in length. (A digit cannot begin a name, however.)

Identifiers may be of any length. However, not all characters will necessarily be significant. There are two types of
identifiers: external and internal. An external identifier will be involved in an external link process. These identifiers,
called external names, include function names and global variable names that are shared between files. If the identifier
is not used in an external link process, it is internal. This type of identifier is called an internal name and includes the
names of local variables, for example. In C89, at least the first 6 characters of an external identifier and at least the
first 31 characters of an internal identifier will be significant. C99 has increased these values. In C99, an external
identifier has at least 31 significant characters and an internal identifier has at least 63 significant characters. In C++, at
least the first 1,024 characters of an identifier are significant.

The underscore is often used for clarity, such as first_time, or to begin a name, such as _count. Uppercase and
lowercase are different. For example, test and TEST are two different variables. C/C++ reserves all identifiers that
begin with two underscores, or an underscore followed by an uppercase letter.
Classes
The class is C++’s basic unit of encapsulation. A class is defined using the class keyword. Classes are not part of the
C language. A class is essentially a collection of variables and functions that manipulate those variables. The variables
and functions that form a class are called members. The general form of class is shown here:

class class-name : inheritance-list {


// private members by default
protected:
// private members that can be inherited
public:
// public members
} object-list;

Here, class-name is the name of the class type. Once the class declaration has been compiled, the class-name
becomes a new type name that can be used to declare objects of the class. The object-list is a comma-separated list
of objects of type class-name. This list is optional. Class objects can be declared later in your program by simply using
the class name. The inheritance-list is also optional. When present, it specifies the base class or classes that the new
class inherits. (See the following section entitled ?Inheritance.?)

A class can include a constructor function and a destructor function. (Either or both are optional.) A constructor is
called when an object of the class is first created. The destructor is called when an object is destroyed. A constructor
has the same name as the class. A destructor has the same name as the class, but is preceded by a ~ (tilde). Neither
constructors nor destructors have return types. In a class hierarchy, constructors are executed in order of derivation
and destructors are executed in reverse order.

By default, all elements of a class are private to that class and can be accessed only by other members of that class.
To allow an element of the class to be accessed by functions that are not members of the class, you must declare
them after the keyword public. For example:
class myclass {
int a, b; // private to myclass
public:
// class members accessible by nonmembers
void setab(int i, int j) { a = i; b = j; }
void showab() { cout << a << ' ' << b << endl; }
};

myclass ob1, ob2;

This declaration creates a class type, called myclass, that contains two private variables, a and b. It also contains two
public functions called setab( ) and showab( ). The fragment also declares two objects of type myclass called ob1 and
ob2.

To allow a member of a class to be inherited, but to otherwise be private, specify it as protected. A protected member
is available to derived classes, but is unavailable outside its class hierarchy.

When operating on an object of a class, use the dot (.) operator to reference individual members. The arrow operator
(–>) is used when accessing an object through a pointer. For example, the following accesses the putinfo( ) function of
ob using the dot operator and the show( ) function using the arrow operator:
struct cl_type {
int x;
float f;
public:
void putinfo(int a, float t) { x = a; f = t; }
void show() { cout << a << ' ' << f << endl; }
};

cl_type ob, *p;


// ...

ob.putinfo(10, 0.23);

p = &ob; // put ob's address in p

p->show(); // displays ob's data

It is possible to create generic classes by using the template keyword. (See template in the keyword summary in
Chapter 5.)
Inheritance
In C++, one class can inherit the characteristics of another. The inherited class is usually called the base class. The
inheriting class is referred to as a derived class. When one class inherits another, a class hierarchy is formed. The
general form for inheriting a class is

class class-name : access base-class-name {


// . . .
};

Here, access determines how the base class is inherited, and it must be either private, public, or protected. (It can also
be omitted, in which case public is assumed if the derived class is a struct, or private if the derived class is a class.) To
inherit more than one class, use a comma-separated list.

If access is public, all public and protected members of the base class become public and protected members of the
derived class, respectively. If access is private, all public and protected members of the base class become private
members of the derived class. If access is protected, all public and protected members of the base class become
protected members of the derived class.

In the following class hierarchy, derived inherits base as private. This means that i becomes a private member of
derived.
class base {
public:
int i;
};

class derived : private base {


int j;
public:
derived(int a) { j = i = a; }
int getj() { return j; }
int geti() { return i; } // OK, derived has access to i
};

derived ob(9); // create a derived object

cout << ob.geti() << " " << ob.getj(); // OK

// ob.i = 10; // ERROR, i is private to derived!


Structures
A structure is created using the keyword struct. In C++, a structure also defines a class. The only difference between
class and struct is that, by default, all members of a structure are public. To make a member private, you must use the
private keyword. The general form of a structure declaration is like this:

struct struct-name : inheritance-list {


// public members by default
protected:
// private members that can be inherited
private:
// private members
} object-list;

In C, several restrictions apply to structures. First, they may contain only data members; member functions are not
allowed. C structures do not support inheritance. Also, all members are public and the keywords public, protected, and
private are not allowed.
Unions
A union is a class type in which all data members share the same memory location. In C++, a union may include both
member functions and data. In
a union, all of its members are public by default. To create private elements, you must use the private keyword. The
general form for declaration of
a union is

union class-name {
// public members by default
private:
// private members
} object-list;

In C, unions may contain only data members and the private keyword is not supported.

The elements of a union overlay each other. For example,


union tom {
char ch;
int x;
} t;

declares union tom , which looks like this in memory (assuming 2-byte integers):

Like a class, the individual variables that comprise the union are referenced using the dot operator. The arrow operator
is used with a pointer to a union.

There are several restrictions that apply to unions. First, a union cannot inherit any other class of any type. A union
cannot be a base class. A union cannot have virtual member functions. No members may be declared as static. A
reference member cannot be used. A union cannot have as a member any object that overloads the = operator.
Finally, no object can be a member of a union if the object’s class explicitly defines a constructor or destructor
function. (Objects that have only the default constructors and destructors are acceptable.)

Programming Tip In C++, it is common practice to use struct when creating C-style structures that
include only data members. A class is usually reserved for creating classes that
contain function members. Sometimes the acronym POD is used to describe a
C-style structure. POD stands for Plain Old Data.

There is a special type of union in C++ called an anonymous union. An anonymous union declaration does not contain
a class name and no objects of that union are declared. Instead, an anonymous union simply tells the compiler that its
member variables are to share the same memory location. However, the variables themselves are referred to directly,
without using the normal dot or arrow operator syntax. The variables that make up an anonymous union are at the
same scope level as any other variable declared within the same block. This implies that the union variable names
must not conflict with any other names valid within their scope. For example, here is an anonymous union:
union { // anonymous union
int a; // a and f share
float f; // the same memory location
};
// ...

a = 10; // access a
cout << f; // access f

Here, a and f both share the same memory location. As you can see, the names of the union variables are referred to
directly without the use of the dot or arrow operator.

All restrictions that apply to unions in general apply to anonymous unions. In addition, anonymous unions must contain
only data—no member functions are allowed. Anonymous unions may not contain the private or protected keywords.
Finally, an anonymous union with namespace scope must be declared as static.
Enumerations
Another type of variable that can be created is called an enumeration. An enumeration is a list of named integer
constants. Thus, an enumeration type is simply a specification of the list of names that belong to the enumeration.

To create an enumeration requires the use of the keyword enum. The general form of an enumeration type is

enum enum-name { list of names } var-list;

The enum-name is the enumeration’s type name. The list of names is comma separated.

For example, the following fragment defines an enumeration of cities called cities and the variable c of type cities.
Finally, c is assigned the value “Houston”.
enum cities { Houston, Austin, Amarillo} c;
c = Houston;

In an enumeration, the value of the first (leftmost) name is, by default, 0; the second name has the value 1; the third
has the value 2; and so on. In general, each name is given a value one greater than the name that precedes it. You
can give a name a specific value by adding an initializer. For example, in the following enumeration, Austin will have
the value 10:
enum cities { Houston, Austin=10, Amarillo };

In this example, Amarillo will have the value 11 because each name will be one greater than the one that precedes it.
C Tags
In C, the name of a structure, union, or enumeration does not define a complete type name. In C++, it does. For
example, the following fragment is valid for C++, but not for C:
struct s_type { int i;
double d;
};
// ...
s_type x; // OK for C++, but not for C

In C++, s_type defines a complete type name and can be used, by itself, to declare objects. In C, s_type defines a tag,
which is not a complete type specifier. In C, you need to precede a tag name with either struct, union, or enum when
declaring objects. For example,
struct s_type x; // now OK for C

The preceding syntax is also permissible in C++, but seldom used.


The Storage Class Specifiers
The type modifiers extern, auto, register, static, and mutable are used to alter the way C/C++ creates storage for
variables. These specifiers precede the type that they modify.

extern

If the extern modifier is placed before a variable name, the compiler will know that the variable has external linkage.
External linkage means that an object is visible outside its own file. In essence, extern tells the compiler the type of a
variable without actually allocating storage for it. The extern modifier is most commonly used when there are two or
more files sharing the same global variables.

auto

auto tells the compiler that the local variable it precedes is created upon entry into a block and destroyed upon exit
from a block. Since all variables defined inside a function are auto by default, the auto keyword is seldom (if ever)
used.

register

When C was first invented, the register modifier could be used only on local integer, character, or pointer variables
because it caused the compiler to attempt to keep that variable in a register of the CPU instead of placing it in
memory. This made all references to that variable extremely fast. The definition of register has since been expanded.
Now, any variable may be specified as register and it is the compiler’s job to optimize accesses to it. For characters,
integers, and pointers, this still means putting them into a register in the CPU, but for other types of data, it may mean
using cache memory, for example. Keep in mind that register is only a request. The compiler is free to ignore it. The
reason for this is that only so many variables can be optimized for speed. When this limit is exceeded, the compiler will
simply ignore further register requests.

static

The static modifier instructs the compiler to keep a local variable in existence during the lifetime of the program
instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making local variables
static allows them to maintain their values between function calls.

The static modifier may also be applied to global variables. When this is done, it causes that variable’s scope to be
restricted to the file in which it is declared. This means that it will have internal linkage. Internal linkage means that an
identifier is known only within its own file.

In C++, when static is used on a class data member, it causes only one copy of that member to be shared by all
objects of its class.

mutable

The mutable specifier applies to C++ only. It allows a member of an object to override constness. That is, a mutable
member can be modified by a const member function.
Type Qualifiers
The type qualifiers provide additional information about the variables they precede.

const

Objects of type const cannot be changed by your program during execution. Also, an object pointed to by a const
pointer cannot be modified. The compiler is free to place variables of this type into read-only memory (ROM). A const
variable will receive its value either from an explicit initialization or by some hardware-dependent means. For example,
const int a = 10;

will create an integer called a with a value of 10 that may not be modified by your program. It can, however, be used in
other types of expressions.

volatile

The modifier volatile tells the compiler that a variable’s value may be changed in ways not explicitly specified by the
program. For example, a global variable’s address may be passed to the clock routine of the operating system and
updated with each clock tick. In this situation, the contents of the variable are altered without any explicit assignment
statements in the program. This is important because compilers will sometimes automatically optimize certain
expressions by making the assumption that the contents of a variable are unchanging inside an expression. This is
done to achieve higher performance. The volatile modifier will prevent this optimization in those rare situations where
this assumption is not the case.

Programming Tip If a class member function is modified by const, it cannot alter the object that invokes
the function. To declare a const member function, put const after its parameter list.
For example,
class MyClass {
int i;
public:
// a const function
void f1(int a) const {
i = a; // Error! can't modify invoking object
}
void f2(int a) {
i = a; // OK, not const function
}
};

As the comments suggest, f1( ) is a const function and it cannot modify the object that
invokes it.

restrict

C99 adds a new type qualifier called restrict. This qualifier applies only to pointers. A pointer qualified by restrict is
initially the only means by which the object it points to can be accessed. Access to the object by another pointer can
occur only if the second pointer is based on the first. Thus, access to the object is restricted to expressions based on
the restrict-qualified pointer. Pointers qualified by restrict are primarily used as function parameters, or to point to
memory allocated via malloc( ) . The restrict qualifier does not change the semantics of a program. restrict is not
supported by C++.
Arrays
You may declare arrays of any data type, including classes. The general form of a singly dimensioned array is

type var-name[size];

where type specifies the data type of each element in the array and size specifies the number of elements in the array.
For example, to declare an integer array x of 100 elements, you would write
int x[100];

This will create an array that is 100 elements long with the first element being 0 and the last being 99. For example,
the following loop will load the numbers 0 through 99 into array x:
for(t=0; t<100; t++) x[t] = t;

Multidimensional arrays are declared by placing the additional dimensions inside additional brackets. For example, to
declare a 10 × 20 integer array, you would write
int x[10][20];

Arrays can be initialized by using a bracketed list of initializers. For example,


int count[5] = { 1, 2, 3, 4, 5 };

In C89 and C++, array dimensions must be specified by constant values. Thus, in C89 and C++, all array dimensions
are fixed at compile time and cannot change over the lifetime of a program. However, in C99, the dimensions of a local
array can be specified by any valid integer expression, including those whose values are known only at compile time.
This is called a variable- length array. Thus, the dimensions of a variable-length array can differ each time its
declaration statement is encountered.
Defining New Type Names Using typedef
You can create a new name for an existing type using typedef. Its general form is

typedef type newname;

For example, the following tells the compiler that feet is another name for int:
typedef int feet;

Now, the following declaration is perfectly legal and creates an integer variable called distance:
feet distance;
Constants
Constants, also called literals, refer to fixed values that cannot be altered by the program. Constants can be of any of
the basic data types. The way each constant is represented depends upon its type. Character constants are enclosed
between single quotes. For example 'a' and '+' are both character constants. Integer constants are specified as
numbers without fractional components. For example, 10 and –100 are integer constants. Floating-point constants
require the use of the decimal point followed by the number’s fractional component. For example, 11.123 is a
floating-point constant. You may also use scientific notation for floating-point numbers.

There are two floating-point types: float and double. Also, there are several flavors of the basic types that are
generated using the type modifiers. By default, the compiler fits a numeric constant into the smallest compatible data
type that will hold it. The only exceptions to the smallest-type rule are floating-point constants, which are assumed to
be of type double. For many programs, the compiler defaults are perfectly adequate. However, it is possible to specify
precisely the type of constant you want.

To specify the exact type of numeric constant, use a suffix. For floating-point types, if you follow the number with an F,
the number is treated as a float. If you follow it with an L, the number becomes a long double. For integer types, the U
suffix stands for unsigned and the L for long. Some examples are shown next:

Data Type Constant Examples

int 1 123 21000 –234

long int 35000L –34L

unsigned int 10000U 987U

float 123.23F 4.34e–3F

double 123.23 12312333 –0.9876324

long double 1001.2L

C99 also allows you to specify a long long integer constant by specifying the suffix LL (or ll).

Hexadecimal and Octal Constants

It is sometimes easier to use a number system based on 8 or 16 instead of 10. The number system based on 8 is
called octal and uses the digits 0 through 7. In octal, the number 10 is the same as 8 in decimal. The base 16 number
system is called hexadecimal and uses the digits 0 through 9 plus the letters A through F, which stand for 10, 11, 12,
13, 14, and 15. For example, the hexadecimal number 10 is 16 in decimal. Because of the frequency with which these
two number systems are used, C/C++ allows you to specify integer constants in hexadecimal or octal instead of
decimal if you prefer. A hexadecimal constant must begin with a 0x (a zero followed by an x) or 0X, followed by the
constant in hexadecimal form. An octal constant begins with a zero. Here are two examples:
int hex = 0x80; // 128 in decimal
int oct = 012; // 10 in decimal

String Constants

C/C++ supports one other type of constant in addition to those of the predefined data types: a string. A string is a set of
characters enclosed by double quotes. For example, "this is a test" is a string. You must not confuse strings with
characters. A single-character constant is enclosed by single quotes, such as 'a'. However, "a" is a string containing
only one letter. String constants are automatically null terminated by the compiler. C++ also supports a string class,
which is described later in this book.

Boolean Constants
C++ specifies two Boolean constants: true and false.

C99, which adds the _Bool type to C, does not specify any built-in Boolean constants. However, if your program
includes the header <stdbool.h>, then the macros true and false are defined. Also, including <stdbool.h> causes the
macro bool to be defined as another name for _Bool. Thus, it is possible to create code that is compatible with both
C99 and C++. Remember, however, that C89 does not define a Boolean type.

Complex Constants

In C99, if you include the header <complex.h>, then the following complex and imaginary constants are defined.

_Complex_I (const float _Complex) i

_Imaginary_I (const float _Imaginary) i

I _Imaginary_I (or _Complex_I if imaginary types are not supported)

Here, i represents the imaginary value, which is the square root of –1.

Backslash Character Constants

Enclosing character constants in single quotes works for most printing characters, but a few, such as the carriage
return, are impossible to enter into your program’s source code from the keyboard. For this reason, C/C++ recognizes
several backslash character constants, also called escape sequences. These constants are listed here:

Code Meaning

\b Backspace

\f Form feed

\n Newline

\r Carriage return

\t Horizontal tab

\" Double quote

\' Single quote

\\ Backslash

\v Vertical tab

\a Alert

\N Octal constant (where N is an octal constant)

\xN Hexadecimal constant (where N is a hexadecimal constant)

\? Question mark

The backslash constants can be used anywhere a character can. For example, the following statement outputs a
newline and a tab and then prints the string “This is a test”.
cout << "\n\tThis is a test";
Chapter 2: Functions, Scopes, Namespaces, and Headers
Functions are the building blocks of a C/C++ program. The elements of a program, including functions, exist within
one or more scopes. In C++, there is a special scope called a namespace. The prototypes for all standard functions
are declared within various headers. These topics are examined here.

Functions
At the heart of a C/C++ program is the function. It is the place in which all program activity occurs. The general form of
a function is

ret-type function_name (parameter list)


{
body of function
}

The type of data returned by a function is specified by ret-type. The parameter list is a comma-separated list of
variables that will receive any arguments passed to the function. For example, the following function has two integer
parameters called i and j and a double parameter called count:
void f(int i, int j, double count)
{ ...

Notice that you must declare each parameter separately.

In C89, if a function’s return type is not explicitly specified, it defaults to int. C++ and C99 do not support
“default-to-int,” although most compilers will still allow it.

Functions terminate and return automatically to the calling procedure when the last brace is encountered. You may
force a return prior to that by using the return statement.

All functions, except those declared as void, return a value. The type of the return value must match the type
declaration of the function. Values are returned via the return statement.

In C++, it is possible to create generic functions using the keyword template. (See template in Chapter 5.)
Recursion
In C/C++, functions can call themselves. This is called recursion, and a function that calls itself is said to be recursive.
A simple example is the function factr( ) shown here, which computes the factorial of an integer. The factorial of a
number N is the product of all the whole numbers from 1 to N. For example, 3 factorial is 1 × 2 × 3, or 6.
// Compute the factorial of a number using recursion.
int factr(int n)
{
int answer;

if(n==1) return 1;
answer = factr(n-1)*n;
return answer;
}

When factr( ) is called with an argument of 1, the function returns 1; otherwise, it returns the product of factr(n–1) * n.
To evaluate this expression, factr( ) is called with n–1 . This process continues until n equals 1 and the calls to the
function begin returning. When factr( ) finally returns to the original caller, the final return value will be the factorial of
the original argument.

Programming Tip Although powerful, recursive functions should be used with care. The recursive
versions of many routines execute a bit more slowly than the iterative equivalent
because of the added overhead of the repeated function calls. Many recursive calls to
a function could cause a stack overrun. Because storage for function parameters and
local variables is on the stack and each new call creates a new copy of these
variables, the stack space could become exhausted. If this happens, a stack overflow
occurs. If this happens in the normal use of a debugged recursive function, try
increasing the stack space allocated to your program.

When writing recursive functions, you must include a conditional statement


somewhere that causes the function to return without the recursive call being
executed. If you don't, once you call the function, it will call itself until the stack is
exhausted. This is a very common error when developing recursive functions. Use
output statements liberally during development so that you can watch what is going
on and abort execution if you see that you have made a mistake.

When a function calls itself, new local variables and parameters are allocated storage on the stack, and the function
code is executed with these new variables from its beginning. A recursive call does not make a new copy of the
function. Only the arguments and local variables are new. As each recursive call returns, the old local variables and
parameters are removed from the stack and execution resumes at the point of the recursive call inside the function.
Recursive functions could be said to “telescope” out and back.
Function Overloading
In C++, functions can be overloaded. When a function is overloaded,two or more functions share the same name.
However, each version of an overloaded function must have a different number and/or type of parameters. (The
function return types may also differ, but this is not necessary.) When an overloaded function is called, the compiler
decides which version of the function to use based upon the type and/or number of arguments, calling the function that
has the closest match. For example, given these three overloaded functions,
void myfunc(int a) { cout << "a is " << a << endl;
}

// overload myfunc
void myfunc(int a, int b) {
cout << "a is " << a << endl;
cout << "b is " << b << endl;
}

// overload myfunc, again


void myfunc(int a, double b) {
cout << "a is " << a << endl;
cout << "b is " << b << endl;
}

the following calls are allowed:


myfunc(10); // calls myfunc(int)
myfunc(12, 24); // calls myfunc(int, int)
myfunc(99, 123.23); // calls myfunc(int, double)

In each case, the type and number of arguments determine which version of myfunc( ) is actually executed.

Function overloading is not supported by C.


Default Arguments
In C++, you may assign a function parameter a default value, which will be used automatically when no corresponding
argument is specified when the function is called. The default value is specified in a manner syntactically similar to a
variable initialization. For example, this function assigns its two parameters default values:
void myfunc(int a = 0, int b = 10)
{ // ...

Given the default arguments, myfunc( ) can be legally called in these


three ways:
myfunc(); // a defaults to 0; b defaults to 10
myfunc(-1); // a is passed -1; b defaults to 10
myfunc(-1, 99); // a is passed -1; b is passed 99

When you create functions that have default arguments, you must specify the default values only once: either in the
function prototype or in its definition. (You cannot specify them each place, even if you use the same values.)
Generally, default values are specified in the prototype.

When giving a function default arguments, remember that you must specify all nondefaulting arguments first. Once
you begin to specify default arguments, there may be no intervening nondefaulting ones.

Default arguments are not supported by C.


Prototypes
In C++, all functions must be prototyped. In C, prototypes are technically optional, but strongly recommended. The
general form of a prototype is shown here:

ret-type name(parameter list);

In essence, a prototype is simply the return type, name, and parameter list of a function, followed by a semicolon.

The following example shows how the function fn( ) is prototyped:


float fn(float x); // prototype

.
.
.
// function definition
float fn(float x)
{
// ...
}

To specify the prototype for a function that takes a variable number of arguments, use three periods at the point at
which the variable number of parameters begin. For example, the printf( ) function could be prototyped like this:
int printf(const char *format, ...);

When specifying the prototype to an overloaded function, each version of that function must have its own prototype.
When a member function is declared within its class, this constitutes a prototype for the function.

In C, to specify the prototype for a function that has no parameters, use void in its parameter list. For example,
int f(void);

In C++, an empty parameter list in a prototype means that the function has no parameters; the void is optional. Thus,
in C++, the preceding prototype can be written like this:
int f();

In C++, you can include void in the parameter list, but doing so is redundant.

Programming Tip Two terms are commonly confused in C/C++ programming: declaration and definition.
Here is what they mean. A declaration specifies the name and type of an object. A
definition allocates storage for it. These definitions apply to functions, too. A function
declaration (prototype) specifies the return type, name, and parameters of a function.
The function itself (that is, the function with its body) is its definition.

In many cases, a declaration is also a definition. For example, when a non-extern


variable is declared, it is also defined. Or, when a function is defined prior to its first
use, its definition also serves as its declaration.
Understanding Scopes and Variable Lifetimes
C and C++ define scope rules, which govern the visibility and lifetime of objects. Although there are several subtleties,
in the most general sense, there are two scopes: global and local.

The global scope exists outside all other scopes. A name declared in the global scope is known throughout the
program. For example, a global variable is available for use by all functions in the program. Global variables stay in
existence the entire duration of the program.

A local scope is defined by a block. That is, a local scope is begun by an opening brace and ends with its closing
brace. A name declared within a local scope is known only within that scope. Because blocks can be nested, local
scopes, too, can be nested. Of course, the most common local scope is the one defined by a function. Local variables
are created when their block is entered, and destroyed when their block is exited. This means that local variables do
not hold their values between function calls. You can use the static modifier, however, to preserve values between
calls.

In C++ and C99, local variables can be declared nearly anywhere within a block. In C89, they must be declared at the
start of a block, before any “action” statements occur. For example, the following code is valid for C++ and C99, but
not for C89:
void f(int a)
{
int a;

a = 10;

int b; // OK for C++ and C99, but not C89

A global variable must be declared outside of all functions, including outside the main( ) function. Global variables are
generally placed at the top of the file, prior to main( ) , for ease of reading and because a variable must be declared
before it is used.

The formal parameters to a function are also local variables and, aside from their job of receiving the value of the
calling arguments, behave and can be used like any other local variable.
Namespaces
In C++, it is possible to create a local scope using the namespace keyword. A namespace defines a declarative
region. Its purpose is to localize names. The general form of namespace is shown here:

namespace name {
// ...
}

Here, name is the name of the namespace. For example,


namespace MyNameSpace {
int count;
}

This creates a namespace called MyNameSpace and the variable count is declared inside it.

Names declared within a namespace can be referred to directly by other statements within the same namespace.
Outside their namespace, names can be accessed two ways. First, you can use the scope resolution operator. For
example, assuming MyNameSpace just shown, the following statement is valid:
MyNameSpace::count = 10;

You can also specify a using statement, which brings the specified name or namespace into the current scope. For
example,
using namespace MyNameSpace;
count = 100;

In this case, count can be referred to directly because it has been brought into the current scope.

When C++ was originally invented, items declared in the C++ library were in the global (i.e., unnamed) namespace.
However, Standard C++ puts all of these items into the std namespace.
The main( ) Function
In a C/C++ program, execution begins at main( ) . (Windows programs call WinMain( ), but this is a special case.) You
must not have more than one function called main( ) . When main( ) terminates, the program is over and control passes
back to the operating system.

The main( ) function is not prototyped. Thus, different forms of main( ) may be used. For both C and C++, the following
versions of main( ) are valid:
int main()
int main(int argc, char *argv[])

As the second form shows, at least two parameters are supported by main( ) . They are argc and argv. (Some
compilers will allow additional parameters.) These two variables will hold the number of command-line arguments and
a pointer to them, respectively. argc is an integer, and its value will always be at least 1 because the program name is
the first argument as far as C/C++ is concerned. argv must be declared as an array of character pointers. Each pointer
points to a command-line argument. Their usage is shown below in a short program that will print your name on the
screen:
#include <iostream>
using namespace std;

int main(int argc, char *argv[])


{
if(argc<2)
cout << "Enter your name.\n";
else
cout << "hello " << argv[1];

return 0;
}
Function Arguments
If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables
are called the formal parameters of the function. They behave like other local variables inside the function and are
created upon entry into the function and destroyed upon exit. As with local variables, you can make assignments to a
function’s formal parameters or use them in any allowable C/C++ expression. Even though these variables perform the
special task of receiving the value of the arguments passed to the function, they can be used like any other local
variable.

In general, subroutines can be passed arguments in one of two ways. The first is called call by value. This method
copies the value of an argument into the formal parameter of the subroutine. Changes made to the parameters of the
subroutine have no effect on the variables used to call it. Call by reference is the second way a subroutine can have
arguments passed to it. In this method, the address of an argument is copied into the parameter. Inside the subroutine,
the argument is accessed through this address. This means that changes made to the parameter affect the variable
used to call the routine.

By default, C and C++ use call by value to pass arguments. This means that you generally cannot alter the variables
used to call the function. Consider the following function:
int sqr(int x)
{
x = x*x;
return x;
}

In this example, when the assignment x = x * x takes place, the only thing modified is the local variable x. The
argument used to call sqr( ) still has its original value.

Remember that only a copy of the value of the argument is passed to a function. What occurs inside the function has
no effect on the variable used in the call.

Passing Pointers

Even though C and C++ use call-by-value parameter passing by default, it is possible to manually construct a call by
reference by passing a pointer to the argument. Since this passes the address of the argument to the function, it is
then possible to change the value of the argument outside the function.

Pointers are passed to functions just like any other value. Of course, it is necessary to declare the parameters as
pointer types. For example, the function swap( ), which exchanges the value of its two integer arguments, is shown
here:
// Use pointer parameters.
void swap(int *x, int *y)
{
int temp;

temp = *x; // save the value at address x


*x = *y; // put y into x
*y = temp; // put x into y
}

It is important to remember that swap( ) (or any other function that uses pointer parameters) must be called with the
addresses of the arguments. The following fragment shows the correct way to call swap( ):
int a, b;

a = 10;
b = 20;
swap(&a, &b);
In this example, swap( ) is called with the addresses of a and b. The unary operator & is used to produce the
addresses of the variables. Therefore, the addresses of a and b, not their values, are passed to the function swap( ).
After the call, a will have the value 20 and b will have the value 10.

Reference Parameters

In C++, it is possible to automatically pass the address of a variable to a function. This is accomplished using a
reference parameter. When using a reference parameter, the address of an argument is passed to the function and
the function operates on the argument, not a copy.

To create a reference parameter, precede its name with the & (ampersand). Inside the function, you can use the
parameter normally, without any need to use the the * (asterisk) operator. The compiler will automatically dereference
the address for you. For example, the following creates a version of swap( ) that uses two reference parameters to
exchange the values of its two arguments:
// Use reference parameters.
void swap(int &x, int &y)
{
int temp;

temp = x; // save the value at address x


x = y; // put y into x
y = temp; // put x into y
}

When invoking swap( ), you simply use the normal function-call syntax. For example,
int a, b;

a = 10;
b = 20;
swap(a, b);

Because x and y are now reference parameters, the addresses of a and b are automatically generated and passed to
the function. Inside the function, the parameter names are used without any need for the * operator because the
compiler automatically refers to the calling arguments each time x and y are used.

Reference parameters apply only to C++.


Constructors and Destructors
In C++, a class may contain a constructor function, a destructor function, or both. A constructor is called when an
object of the class is first created and the destructor is called when an object of the class is destroyed. A constructor
has the same name as the class of which it is a member and the destructor’s name is the same as its class, except
that it is preceded by a ~ . Neither constructors nor destructors have return values.

Constructors may have parameters. You can use these parameters to pass values to a constructor, which can be
used to initialize an object. The arguments that are passed to the parameters are specified when an object is created.
For example, this fragment illustrates how to pass a constructor an argument:
class myclass {
int a;
public:
myclass(int i) { a = i; } // constructor
~myclass() { cout << "Destructing..."; }
};

// ...

myclass ob(3); // pass 3 to i

When ob is declared, the value 3 is passed to the constructor’s parameter i, which is then assigned to a.

In an inheritance hierarchy, a base class’ constructor is automatically called before the derived class’ constructor. If
you need to pass arguments to the base class constructor, you do so by using an expanded form of the derived class’
constructor declaration. Its general form is shown here:

derived-constructor(arg-list) : base1(arg-list),
base2(arg-list),
// ...
baseN(arg-list)
{
// body of derived constructor
}

Here, base1 through baseN are the names of the base classes inherited by the derived class. Notice that a colon
separates the derived class’ constructor declaration from the base class specifications, and that the base class
specifications are separated from each other by commas, in the case of multiple base classes. Here is an example:
class base {
protected:
int i;
public:
base(int x) { i = x; }

// ...
};

class derived: public base {


int j;
public:
// derived uses x; y is passed along to base.
derived(int x, int y): base(y) { j = x; }

void show() { cout << i << " " << j << "\n"; }

// ...
};
Here, derived’s constructor is declared as taking two parameters, x and y. However, derived( ) uses only x; y is passed
along to base( ) . In general, the derived class’ constructor must declare the parameter(s) that it requires as well as any
required by the base class. As the example illustrates, any values required by the base class are passed to it in the
base class’ argument list specified after the colon.
Function Specifiers
C++ defines three function specifiers: inline, virtual, and explicit. The inline specifier is also supported by C99. inline is
a request to the compiler to expand a function’s code inline rather than to call it. If the compiler cannot inline the
function, it is free to ignore the request. Both member and nonmember functions may be specified as inline.

Programming Tip There are two ways a constructor can initialize member variables. First, it can
explicitly assign them values inside the body of the constructor. For example,
consider MyClass, shown here, which has two integer data members callednumA and
numB . These member variables are initialized inside theMyClass constructor.
class MyClass {
int numA;
int numB;
public:
/* Initialize numA and numB inside the MyClass
constructor using normal syntax. */
MyClass(int x, int y) {
numA = x;
numB = y;
}
// ...
};

Assigning initial values to member variables numA and numB inside the constructor,
as MyClass does, is a common approach, and is the way that member initialization is
accomplished for many classes. However, this approach won't work in all cases. For
example, if numA and numB were specified as const, like this,
class MyClass {
const int numA; // const member
const int numB; // const member

then they could not be given values by the MyClass constructor because const
variables must be initialized and cannot be assigned values after the fact. Similar
problems arise when using reference members, which must be initialized, and when
using class members that don't have default constructors. To solve these types of
problems, C++ supports a second member initialization syntax, which gives a class
member an initial value when an object of the class is created.

The member initialization syntax is similar to that used to call a base class
constructor. Here is the general form:
constructor(arg-list) : member1(initializer),
member2(initializer),
// ...
memberN(initializer)
{
// body of constructor
}

The members that you want to initialize are specified in a comma- separated list that
goes after the constructor's declaration and before the body of the constructor. Notice
the use and placement of the colon. You can mix calls to base class constructors with
member initializations in the same list.

Here is MyClass rewritten so thatnumA and numB are const members that are given
values using the member initialization syntax.
class MyClass {
const int numA; // const member
const int numB; // const member
public:
// Initialize using initialization syntax.
MyClass(int x, int y) : numA(x), numB(y) { }
// ...
};

Here, numA is initialized with the value passed inx, and numB is initialized with the
value passed in y. Even though numA and numB are now const, they can be given
initial values when a MyClass object is created because the member initialization
syntax is used.

One last point: Class members are constructed and initialized in the order in which
they are declared in a class, not in the order in which their initializers occur.

A virtual function is defined in a base class and overridden by a derived class. Virtual functions are how C++ supports
polymorphism.

The explicit specifier applies only to constructors. Any time that you have a constructor that requires only one
argument, you can use either ob(x) or ob = x to initialize an object. The reason for this is that whenever you create a
constructor that takes one argument, you are also implicitly creating a conversion from the type of that argument to the
type of the class. A constructor specified as explicit will be used only when an initialization uses the normal constructor
syntax, ob(x). No automatic conversion will take place and ob = x will not be allowed. Thus, an explicit constructor
creates a “nonconverting constructor.”
Linkage Specification
Because it is common to link a C++ function with functions generated by another language (such as C), C++ allows
you to specify a linkage specification that tells the compiler how to link a function. It has this general form:

extern "language" function-prototype

As you can see, the linkage specification is an extension to the extern keyword. Here, language denotes the language
to which you want the function to link. C and C++ linkages are guaranteed to be supported. Your compiler may support
other linkages, too. To declare several functions using the same linkage specification, you can use this general form:

extern"language" {
function-prototypes
}

The linkage specification applies only to C++. It is not supported by C.


The C and C++ Standard Libraries
Neither C nor C++ have keywords that perform I/O, manipulate strings, perform various mathematical computations, or
a number of other useful procedures. These things are accomplished by using a set of predefined library functions that
are supplied with the compiler. There are two basic styles of libraries: the C function library, which is supplied with all C
and C++ compilers, and the C++ class library, which applies only to C++. Both libraries are summarized later in this
guide.

Before your program can use a library function, it must include the appropriate header. In general, headers are usually
files, but they are not necessarily files. It is permissible for a compiler to predefine the contents of a header internally.
However, for all practical purposes, the standard C headers are contained in files that correspond to their names. The
following table shows the standard headers defined by C89, along with those added by the 1995 Amendment 1.

Header Supports

<assert.h> The assert( ) macro

<ctype.h> Character handling

<errno.h> Error reporting

<float.h> Implementation-dependent floating-point limits

<iso646.h> Macros that correspond to various operators, such as && and ^; added in 1995 by
Amendment 1

<limits.h> Various implementation-dependent limits

<locale.h> Localization

<math.h> Various definitions used by the math library

<setjmp.h> Nonlocal jumps

<signal.h> Signal values

<stdarg.h> Variable-length argument lists

<stddef.h> Commonly used constants

<stdio.h> File I/O

<stdlib.h> Miscellaneous declarations

<string.h> String functions

<time.h> System time and date functions

<wchar.h> Multibyte and wide-character functions; added in 1995 by Amendment 1

<wctype.h> Multibyte and wide-character classification functions; added in 1995 by Amendment 1

The following table shows those headers added by C99.

Header Supports

<complex.h> Complex arithmetic.

<fenv.h> The floating-point status flags and other aspects of the floating-point environment.

<inttypes.h> Standard, portable set of integer type names; also supports functions that handle
greatest-width integers.
Header Supports

<stdbool.h> Boolean data types and defines the macrobool, which helps with C++ compatibility.

<stdint.h> Standard, portable set of integer type names. This file is included byinttypes.h
< >.

<tgmath.h> Type-generic floating-point macros.

For C++, headers are specified using standard header names, which do not end with .h. Thus, the C++ headers do not
specify filenames. Instead, they are simply standard identifiers that the compiler can handle as it sees fit. This means
that a header may be mapped to a filename, but this is not required. The C++ headers are shown here. Those
associated either directly or indirectly with the Standard Template Library (STL) are indicated.

C++ Header Supports

<algorithm> Various operations on containers (STL)

<bitset> Bitsets (STL)

<complex> Complex numbers

<deque> Double-ended queues (STL)

<exception> Exception handling

<fstream> Stream-based file I/O

<functional> Various function objects (STL)

<iomanip> I/O manipulators

<ios> Low-level I/O classes

<iosfwd> Forward declarations for I/O system

<iostream> Standard I/O classes

<istream> Input streams

<iterator> Access to contents of containers (STL)

<limits> Various implementation limits

<list> Linear lists (STL)

<locale> Localization-specific information

<map> Maps (keys with values) (STL)

<memory> Memory allocation via allocators (STL)

<new> Memory allocation using new

<numeric> General-purpose numeric operations (STL)

<ostream> Output streams

<queue> Queues (STL)

<set> Sets (STL)

<sstream> String streams

<stack> Stacks (STL)

<stdexcept> Standard exceptions


C++ Header Supports

<streambuf> Buffered streams

<string> Standard string class (STL)

<typeinfo> Runtime type information

<utility> General purpose templates (STL)

<valarray> Operations on arrays containing values

<vector> Vectors (dynamic arrays) (STL)

C++ also defines the following headers that correspond to the C headers (except those added by C99).

<cassert> <cctype> <cerrno>

<cfloat> <ciso646> <climits>

<clocale> <cmath> <csetjmp>

<csignal> <cstdarg> <cstddef>

<cstdio> <cstdlib> <cstring>

<ctime> <cwchar> <cwctype>

In standard C++, all of the information relating to the standard library is defined under the std namespace. Thus, to
gain direct access to these items, you will need to include the following using statement after including the necessary
headers:
using namespace std;

Alternatively, you can qualify each library identifier with std::, such as std::cout, rather than bringing the entire library
into the global namespace. However, qualifying each name can get to be tedious.

Programming Tip If you are using an older C++ compiler, then it may not support the modern-style C++
headers or the namespace command. If this is the case, then you will need to use the
older, traditional-style headers. These use the same names as the modern headers
but include the .h (thus, they resemble C headers). For example, the following
includes <iostream> using the traditional approach:
#include <iostream.h>

When using the traditional-style header, all of the names defined by the header are
placed in the global namespace, not the one defined by std. Thus, no using statement
is required.
Chapter 3: Operators
C/C++ has a rich set of operators that can be divided into the following classes: arithmetic, relational and logical,
bitwise, pointer, assignment, I/O, and miscellaneous.

Arithmetic Operators
C/C++ has the following seven arithmetic operators:

Operator Action

– Subtraction, unary minus

+ Addition

* Multiplication

/ Division

% Modulus

–– Decrement

++ Increment

The + , –, *, and / operators work in the expected fashion. The % operator returns the remainder of an integer division.
The increment and decrement operators increase or decrease the operand by one.

These operators have the following order of precedence:

Precedence Operators

Highest ++ – – – (unary minus)

* / %

Lowest + –

Operators on the same precedence level are evaluated left to right.


Relational and Logical Operators
The relational and logical operators are used to produce Boolean (true/false) results and are often used together. In
C/C++, any nonzero number evaluates as true. Zero is false. In C++, the outcome of the relational and logical
operators is of type bool. In C, the outcome is a zero or nonzero integer. The relational operators are listed here:

Operator Meaning

> Greater than

>= Greater than or equal

< Less than

<= Less than or equal

== Equal

!= Not equal

The logical operators are shown here:

Operator Meaning

&& AND

|| OR

! NOT

The relational operators compare two values, producing a Boolean result. The logical operators connect two Boolean
values or, in the case of ! , reverse a value. The precedence of these operators is shown here:

Precedence Operators

Highest !

> >= < <=

== !=

&&

Lowest ||

As an example, the following if statement evaluates to true and prints the line x is less than 10:
x = 9;
if(x < 10) cout << "x is less than 10";

However, in the following example, no message is displayed because both operands associated with && must be true
for the outcome to be true:
x = 9;
y = 9;
if(x < 10 && y > 10)
cout << "This will not print.";
The Bitwise Operators
C and C++ provide operators that act upon the actual bits that comprise a value. The bitwise operators can be used
only on integral types. The bitwise operators are as follows:

Operator Meaning

& AND

| OR

^ XOR

~ One’s complement

>> Right shift

<< Left shift

&, |, and ^

The truth tables for &, |, and ^ are as follows:

p q p&q p|q p^q

0 0 0 0 0

0 1 0 1 1

1 1 1 1 0

1 0 0 1 1

These rules are applied to each bit in each operand when the bitwise AND, OR, and XOR operations are performed.

For example, a sample bitwise AND operation is shown here:

0100 1101

& 0011 1011

0000 1001

A bitwise OR operation looks like this:

0100 1101

| 0011 1011

0111 1111

A bitwise XOR operation is shown here:

0100 1101

^ 0011 1011

0111 0110
The One’s Complement Operator

The one’s complement operator, ~ , will invert all the bits in its operand. For example, if a character variable, ch, has
the bit pattern
0011 1001

then
ch = ~ch;

places the bit pattern


1100 0110

into ch.

The Shift Operators

The right (>>) and left (<<) shift operators shift all bits in an integral value by the specified amount. As bits are shifted
off one end, zeros are brought in the other end. (If the value being shifted is a negative, signed number and a right
shift is performed, then ones are shifted in to preserve the sign.) The number on the right side of the shift operator
specifies the number of positions to shift. The general form of each shift operator is

value >> number


value << number

Here, number specifies the number of positions to shift value.

Given this bit pattern (and assuming an unsigned value),


0011 1101

a shift right yields


0001 1110

while a shift left produces


0111 1010

Programming Tip A shift right is effectively a division by 2, and a shift left is a multiplication by 2. For
many computers, a shift is faster than a multiply or a divide. Therefore, if you need a
fast way to multiply or divide by 2, consider using the shift operators. For example,
the following code fragment will first multiply and then divide the value in x by 2:
int x;

x = 10;
x = x << 1;
x = x >> 1;

Of course, when using the shift operators to perform multiplication, you must be
careful not to shift bits off the end.

The precedence of the bitwise operators is shown here:

Precedence Operators

Highest ~

>> <<

&

^
Random documents with unrelated
content Scribd suggests to you:
CHAPTER XXXV
Do not think that what we have laid down in the preceding chapters
on the importance, obscurity, and difficulty of the subject, and its
unsuitableness for communication to ordinary persons, includes the
doctrine of God’s incorporeality and His exemption from all affections
(πάθη). This is not the case. For in the same way as all people must
be informed, and even children must be trained in the belief that
God is One, and that none besides Him is to be worshipped, so must
all be taught by simple authority that God is incorporeal; that there
is no similarity in any way whatsoever between Him and His
creatures; that His existence is not like the existence of His
creatures, His life not like that of any living being, His wisdom not
like the wisdom of the wisest of men; and that the difference
between Him and His creatures is not merely quantitative, but
absolute [as between two individuals of two different classes]; I
mean to say that all must understand that our wisdom and His, or
our power and His do not differ quantitatively or qualitatively, or in a
similar manner; for two things, of which the one is strong and the
other weak, are necessarily similar, belong to the same class, and
can be included in one definition. The same is the case with all other
comparisons; they can only be made between two things belonging
to the same class, as has been shown in works on Natural Science.
Anything predicated of God is totally different from our attributes; no
definition can comprehend both; therefore His existence and that of
any other being totally differ from each other, and the term
existence is applied to both homonymously, as I shall explain.

This suffices for the guidance of children and of ordinary persons


who must believe that there is a Being existing, perfect, incorporeal,
not inherent in a body as a force in it—God, who is above all kinds of
deficiency, above all affections. But the question concerning the
attributes of God, their inadmissibility, and the meaning of those
attributes which are ascribed to Him; concerning the Creation, His
Providence, in providing for everything; concerning His will, His
perception, His knowledge of everything; concerning prophecy and
its various degrees; concerning the meaning of His names which
imply the idea of unity, though they are more than one; all these
things are very difficult problems, the true “Secrets of the Law” the
[50]“secrets” mentioned so frequently in the books of the Prophets,
and in the words of our Teachers, the subjects of which we should
only mention the headings of the chapters, as we have already
stated, and only in the presence of a person satisfying the above-
named conditions.

That God is incorporeal, that He cannot be compared with His


creatures, that He is not subject to external influence; these are
things which must be explained to every one according to his
capacity, and they must be taught by way of tradition to children and
women, to the stupid and ignorant, as they are taught that God is
One, that He is eternal, and that He alone is to be worshipped.
Without incorporeality there is no unity, for a corporeal thing is in
the first case not simple, but composed of matter and form which
are two separate things by definition, and secondly, as it has
extension it is also divisible. When persons have received this
doctrine, and have been trained in this belief, and are in
consequence at a loss to reconcile it with the writings of the
Prophets, the meaning of the latter must be made clear and
explained to them by pointing out the homonymity and the figurative
application of certain terms discussed in this part of the work. Their
belief in the unity of God and in the words of the Prophets will then
be a true and perfect belief.
Those who are not sufficiently intelligent to comprehend the true
interpretation of these passages in the Bible, or to understand that
the same term admits of two different interpretations, may simply be
told that the scriptural passage is clearly understood by the wise, but
that they should content themselves with knowing that God is
incorporeal, that He is never subject to external influence, as
passivity implies a change, while God is entirely free from all change,
that He cannot be compared to anything besides Himself, that no
definition includes Him together with any other being, that the words
of the Prophets are true, and that difficulties met with may be
explained on this principle. This may suffice for that class of persons,
and it is not proper to leave them in the belief that God is corporeal,
or that He has any of the properties of material objects, just as there
is no need to leave them in the belief that God does not exist, that
there are more Gods than one, or that any other being may be
worshipped.
[Contents]
CHAPTER XXXVI
I shall explain to you, when speaking on the attributes of God, in
what sense we can say that a particular thing pleases Him, or
excites His anger and His wrath, and in reference to certain persons
that God was pleased with them, was angry with them, or was in
wrath against them. This is not the subject of the present chapter; I
intend to explain in it what I am now going to say. You must know,
that in examining the Law and the books of the Prophets, you will
not find the expressions “burning anger,” “provocation,” or “jealousy”
applied to God except in reference to idolatry; and that none but the
idolater called “enemy,” “adversary,” or “hater of the Lord.” Comp.
“And ye serve other gods, … and then the Lord’s wrath will be
kindled against you” (Deut. xi. 16, 17); “Lest the anger of the Lord
thy God be kindled against thee.” etc. (ib. vi. 15); “To provoke him to
anger through the work of your hands” (ib. xxxi. 29); “They have
moved [51]me to jealousy with that which is not God; they have
provoked me to anger with their vanities” (ib. xxxii. 21); “For the
Lord thy God is a jealous God” (ib. vi. 15); “Why have they provoked
me to anger with their graven images, and with strange vanities?”
(Jer. viii. 19); “Because of the provoking of his sons and of his
daughters” (Deut. xxxii. 19); “For a fire is kindled in mine anger” (ib.
22); “The Lord will take vengeance on His adversaries, and he
reserveth wrath for his enemies” (Nah. i. 2); “And repayeth them
that hate Him” (Deut. vii. 10); “Until He hath driven out His enemies
from before Him” (Num. xxxii. 21); “Which the Lord thy God hateth”
(Deut. xvi. 22); “For every abomination to the Lord, which He
hateth, have they done unto their gods” (ib. xii. 31). Instances like
these are innumerable; and if you examine all the examples met
with in the holy writings, you will find that they confirm our view.
The Prophets in their writings laid special stress on this, because it
concerns errors in reference to God, i.e., it concerns idolatry. For if
any one believes that, e.g., Zaid is standing, while in fact he is
sitting, he does not deviate from truth so much as one who believes
that fire is under the air, or that water is under the earth, or that the
earth is a plane, or things similar to these. The latter does not
deviate so much from truth as one who believes that the sun
consists of fire, or that the heavens form a hemisphere, and similar
things; in the third instance the deviation from truth is less than the
deviation of a man who believes that angels eat and drink, and the
like. The latter again deviates less from truth than one who believes
that something besides God is to be worshipped; for ignorance and
error concerning a great thing, i.e., a thing which has a high position
in the universe, are of greater importance than those which refer to
a thing which occupies a lower place;—by “error” I mean the belief
that a thing is different from what it really is; by “ignorance,” the
want of knowledge respecting things the knowledge of which can be
obtained.

If a person does not know the measure of the cone, or the sphericity
of the sun, it is not so important as not to know whether God exists,
or whether the world exists without a God; and if a man assumes
that the cone is half (of the cylinder), or that the sun is a circle, it is
not so injurious as to believe that God is more than One. You must
know that idolaters when worshipping idols do not believe that there
is no God besides them; and no idolater ever did assume that any
image made of metal, stone, or wood has created the heavens and
the earth, and still governs them. Idolatry is founded on the idea
that a particular form represents the agent between God and His
creatures. This is plainly said in passages like the following: “Who
would not fear thee, O king of nations?” (Jer. x. 7); “And in every
place incense is offered unto my name” (Mal. i. 11); by “my name”
allusion is made to the Being which is called by them [i.e., the
idolaters] “the First Cause.” We have already explained this in our
larger work (Mishneh Torah, I. On Idolatry, chap. i.), and none of our
co-religionists can doubt it.

The infidels, however, though believing in the existence of the


Creator, attack the exclusive prerogative of God, namely, the service
and worship which was commanded, in order that the belief of the
people in His existence should be firmly established, in the words,
“And you shall serve the Lord,” etc. (Exod. xxiii. 25). By transferring
that prerogative to other beings, they [52]cause the people, who only
notice the rites, without comprehending their meaning or the true
character of the being which is worshipped, to renounce their belief
in the existence of God. They were therefore punished with death;
comp. “Thou shalt save alive nothing that breatheth” (Deut. xx. 16).
The object of this commandment, as is distinctly stated, is to
extirpate that false opinion, in order that other men should not be
corrupted by it any more; in the words of the Bible “that they teach
you not,” etc. (ib. 18). They are called “enemies,” “foes,”
“adversaries”; by worshipping idols they are said to provoke God to
jealousy, anger, and wrath. How great, then, must be the offence of
him who has a wrong opinion of God Himself, and believes Him to be
different from what He truly is, i.e., assumes that He does not exist,
that He consists of two elements, that He is corporeal, that He is
subject to external influence, or ascribes to Him any defect
whatever. Such a person is undoubtedly worse than he who worships
idols in the belief that they, as agents, can do good or evil.

Therefore bear in mind that by the belief in the corporeality or in


anything connected with corporeality, you would provoke God to
jealousy and wrath, kindle His fire and anger, become His foe, His
enemy, and His adversary in a higher degree than by the worship of
idols. If you think that there is an excuse for those who believe in
the corporeality of God on the ground of their training, their
ignorance or their defective comprehension, you must make the
same concession to the worshippers of idols; their worship is due to
ignorance, or to early training, “they continue in the custom of their
fathers.” (T. B. Hullin, 13a) You will perhaps say that the literal
interpretation of the Bible causes men to fall into that doubt, but you
must know that idolaters were likewise brought to their belief by
false imaginations and ideas. There is no excuse whatever for those
who, being unable to think for themselves, do not accept [the
doctrine of the incorporeality of God] from the true philosophers. I
do not consider those men as infidels who are unable to prove the
incorporeality, but I hold those to be so who do not believe it,
especially when they see that Onkelos and Jonathan avoid [in
reference to God] expressions implying corporeality as much as
possible. This is all I intended to say in this chapter.

[Contents]
CHAPTER XXXVII
The Hebrew term panim (face) is homonymous; most of its various
meanings have a figurative character. It denotes in the first place the
face of a living being; comp. “And all faces are turned into paleness”
(Jer. xxx. 6); “Wherefore are your faces so sad?” (Gen. xl. 7). In this
sense the term occurs frequently.

The next meaning of the word is “anger”; comp. “And her anger
(paneha) was gone” (1 Sam. i. 18). Accordingly, the term is
frequently used in reference to God in the sense of anger and wrath;
comp. “The anger (pene) of the Lord hath divided them” (Lam. iv.
16); “The anger (pene) of the Lord is against them that do evil” (Ps.
xxxiv. 17); “Mine anger (panai) shall go and I will give thee rest”
(Exod. xxxiii. 14); “Then will I set mine anger” (panai) (Lev. xx. 3);
there are many other instances.

Another meaning of the word is “the presence and existence of a


person”; [53]comp. “He died in the presence (pene) [i.e., in the
lifetime] of all his brethren” (Gen. xxv. 18); “And in the presence
(pene) of all the people I will be glorified” (Lev. x. 3); “He will surely
curse thee in thy very presence” (paneka) (Job i. 11). In the same
sense the word is used in the following passage, “And the Lord
spake unto Moses face to face,” i.e., both being present, without any
intervening medium between them. Comp. “Come, let us look one
another in the face” (2 Kings xiv. 8); and also “The Lord talked with
you face to face” (Deut. v. 4); instead of which we read more plainly
in another place, “Ye heard the voice of the words, but saw no
similitude; only ye heard a voice” (ib. iv. 12). The hearing of the
voice without seeing any similitude is termed “face to face.” Similarly
do the words, “And the Lord spake unto Moses face to face”
correspond to “There he heard the voice of one speaking unto him”
(Num. vii. 89), in the description of God’s speaking to Moses. Thus it
will be clear to you that the perception of the Divine voice without
the intervention of an angel is expressed by “face to face.” In the
same sense the word panim must be understood in “And my face
(panai) shall not be seen” (Exod. xxxiii. 23); i.e., my true existence,
as it is, cannot be comprehended.

The word panim is also used in Hebrew as an adverb of place, in the


sense of “before,” or “between the hands.” In this sense it is
frequently employed in reference to God; so also in the passage,
“And my face (panai) shall not be seen,” according to Onkelos, who
renders it, “And those before me shall not be seen.” He finds here an
allusion to the fact, that there are also higher created beings of such
superiority that their true nature cannot be perceived by man; viz.,
the ideals, separate intellects, which in their relation to God are
described as being constantly before Him, or between His hands,
i.e., as enjoying uninterruptedly the closest attention of Divine
Providence. He, i.e., Onkelos, considers that the things which are
described as completely perceptible are those beings which, as
regards existence, are inferior to the ideals, viz., substance and
form; in reference to which we are told, “And thou shalt see that
which is behind me” (ibid.), i.e., beings, from which, as it were, I
turn away, and which I leave behind me. This figure is to represent
the utter remoteness of such beings from the Deity. You shall later
on (chap. liv.) hear my explanation of what Moses, our teacher,
asked for.

The word is also used as an adverb of time, meaning “before.”


Comp. “In former time (le-phanim) in Israel” (Ruth iv. 7); “Of old (le-
phanim) hast Thou laid the foundation of the earth” (Ps. cii. 25).
Another signification of the word is “attention and regard.” Comp.
“Thou shalt not have regard (pene) to the poor” (Lev. xx. 15); “And
a person receiving attention (panim)” (Isa. iii. 3); “Who does not
show regard (panim),” etc. (Deut. x. 17, etc.). The word panim
(face) has a similar signification in the blessing, “The Lord turn his
face to thee” (i.e., The Lord let his providence accompany thee),
“and give thee peace.”

[Contents]
CHAPTER XXXVIII
The Hebrew term aḥor is a homonym. It is a noun, signifying “back.”
Comp. “Behind (aḥare) the tabernacle” (Exod. xxvi. 12); “The spear
came out behind him (aḥarav)” (2 Sam. ii. 23). [54]

It is next used in reference to time, signifying “after”; “neither after


him (aḥarav) arose there any like him” (2 Kings xxiii. 25); “After
(aḥar) these things” (Gen. xv. 1). In this sense the word occurs
frequently.

The term includes also the idea of following a thing and of


conforming with the moral principles of some other being. Comp. “Ye
shall walk after (aḥare) the Lord, your God” (Deut. xiii. 5); “They
shall walk after (aḥare) the Lord” (Hos. xi. 10), i.e., follow His will,
walk in the way of His actions, and imitate His virtues; “He walked
after (aḥare) the commandment” (ib. v. 11). In this sense the word
occurs in Exodus xxxiii. 20, “And thou shalt see my back” (aḥorai);
thou shalt perceive that which follows me, is similar to me, and is
the result of my will, i.e., all things created by me, as will be
explained in the course of this treatise.

[Contents]
CHAPTER XXXIX
The Hebrew leb (heart) is a homonymous noun, signifying that
organ which is the source of life to all beings possessing a heart.
Comp. “And thrust them through the heart of Absalom” (1 Sam. xviii.
14).

This organ being in the middle of the body, the word has been
figuratively applied to express “the middle part of a thing.” Comp.
“unto the midst (leb) of heaven” (Deut. iv. 11); “the midst (labbath)
of fire” (Exod. iii. 2).

It further denotes “thought.” Comp. “Went not mine heart with


thee?” (2 Kings v. 26), i.e., I was with thee in my thought when a
certain event happened. Similarly must be explained, “And that ye
seek not after your own heart” (Num. xv. 39), i.e., after your own
thoughts; “Whose heart (i.e., whose thought), turneth away this
day” (Deut. xxix. 18).

The word further signifies “counsel.” Comp. “All the rest of Israel
were of one heart (i.e., had one plan) to make David king” (1 Chron.
xii. 38); “but fools die for want of heart,” i.e., of counsel; “My heart
(i.e., my counsel) shall not turn away from this so long as I live” (Job
xxvii. 6); for this sentence is preceded by the words, “My
righteousness I hold fast, and will not let it go”; and then follows,
“my heart shall never turn away from this.”—As regards the
expression yeḥeraf, I think that it may be compared with the same
verb in the form neḥrefet, “a handmaid betrothed (neḥrefet) to a
man” (Lev. xix. 20), where neḥrefetḥ is similar in meaning to the
Arabic munḥarifat, “turning away,” and signifies “turning from the
state of slavery to that of marriage.”
Leb (heart) denotes also “will”; comp. “And I shall give you pastors
according to my will (libbi)” (Jer. iii. 15), “Is thine heart right as my
heart is?” (2 Kings x. 15), i.e., is thy will right as my will is? In this
sense the word has been figuratively applied to God. Comp. “That
shall do according to that which is in mine heart and in my soul” (1
Sam. ii. 35), i.e., according to My will; “And mine eyes and mine
heart (i.e., My providence and My will) shall be there perpetually” (1
Kings ix. 3).

The word is also used in the sense of “understanding.” Comp. “For


vain man will be endowed with a heart” (Job xi. 12), i.e., will be
wise; “A wise man’s heart is at his right hand” (Eccles. x. 2), i.e., his
understanding is engaged in perfect thoughts, the highest problems.
Instances of this kind are numerous. It is in this sense, namely, that
of understanding, that the [55]word is used whenever figuratively
applied to God; but exceptionally it is also used in the sense of “will.”
It must, in each passage, be explained in accordance with the
context. Also, in the following and similar passages, it signifies
“understanding”; “Consider it in thine heart” (Deut. iv. 39); “And
none considereth in his heart” (Isa. xliv. 19). Thus, also, “Yet the
Lord hath not given you an heart to perceive,” is identical in its
meaning with “Unto thee it was shown that thou mightest know”
(Deut. iv. 35).

As to the passage, “And thou shalt love the Lord thy God with all
thine heart” (Ib. vi. 5), I explain “with all thine heart” to mean “with
all the powers of thine heart,” that is, with all the powers of the
body, for they all have their origin in the heart; and the sense of the
entire passage is: make the knowledge of God the aim of all thy
actions, as we have stated in our Commentary on the Mishnah
(Aboth, Eight Chapters, v.), and in our Mishneh Torah, yesode
hatorah, chap. ii. 2.
[Contents]
CHAPTER XL
Ruaḥ is a homonym, signifying “air,” that is, one of the four
elements. Comp. “And the air of God moved” (Gen. i. 2).

It denotes also, “wind.” Comp. “And the east wind (ruaḥ) brought
the locusts” (Exod. x. 13); “west wind” (ruaḥ) (ib. 19). In this sense
the word occurs frequently.

Next, it signifies “breath.” Comp. “A breath (ruaḥ) that passeth away,


and does not come again” (Ps. lxxviii. 39); “wherein is the breath
(ruaḥ) of life” (Gen. vii. 15).

It signifies also that which remains of man after his death, and is not
subject to destruction. Comp. “And the spirit (ruaḥ) shall return unto
God who gave it” (Eccles. xii. 7).

Another signification of this word is “the divine inspiration of the


prophets whereby they prophesy”—as we shall explain, when
speaking on prophecy, as far as it is opportune to discuss this
subject in a treatise like this.—Comp. “And I will take of the spirit
(ruaḥ) which is upon thee, and will put it upon them” (Num. xi. 17);
“And it came to pass, when the spirit (ruaḥ) rested upon them” (ib.
25); “The spirit (ruaḥ) of the Lord spake by me” (2 Sam. xxiii. 2).
The term is frequently used in this sense.

The meaning of “intention,” “will,” is likewise contained in the word


ruaḥ. Comp. “A fool uttereth all his spirit” (ruaḥ) (Prov. xxix. 11), i.e.,
his intention and will; “And the spirit (ruaḥ) of Egypt shall fail in the
midst thereof, and I will destroy the counsel thereof” (Isa. xix. 3),
i.e., her intentions will be frustrated, and her plans will be obscured;
“Who has comprehended the spirit (ruaḥ) of the Lord, or who is
familiar with his counsel that he may tell us?” (Isa. xl. 13), i.e., Who
knows the order fixed by His will, or perceives the system of His
Providence in the existing world, that he may tell us? as we shall
explain in the chapters in which we shall speak on Providence.

Thus the Hebrew ruaḥ, when used in reference to God, has


generally the fifth signification; sometimes, however, as explained
above, the last signification, viz., “will.” The meaning of the word in
each individual case is therefore to be determined by the context.
[56]

[Contents]
CHAPTER XLI
The Hebrew nefesh (soul) is a homonymous noun, signifying the
vitality which is common to all living, sentient beings. E.g. “wherein
there is a living soul” (nefesh) (Gen. i. 30). It denotes also blood, as
in “Thou shalt not eat the blood (nefesh) with the meat” (Deut. xii.
23). Another signification of the term is “reason,” that is, the
distinguishing characteristic of man, as in “As the Lord liveth that
made us this soul” (Jer. xxxviii. 16). It denotes also the part of man
that remains after his death (nefesh, soul); comp. “But the soul
(nefesh) of my lord shall be bound in the bundle of life” (1 Sam. xxv.
29). Lastly, it denotes “will”; comp. “To bind his princes at his will”
(be-nafsho) (Ps. cv. 22); “Thou wilt not deliver me unto the will (be-
nefesh) of my enemies” (Ps. xli. 3); and according to my opinion, it
has this meaning also in the following passages, “If it be your will
(nafshekem) that I should bury my dead” (Gen. xxiii. 8); “Though
Moses and Samuel stood before me, yet my will (nafshi) could not
be toward this people” (Jer. xv. 1), that is, I had no pleasure in
them, I did not wish to preserve them. When nefesh is used in
reference to God, it has the meaning “will,” as we have already
explained with reference to the passage, “That shall do according to
that which is in my will (bi-lebabi) and in mine intention (be-nafshi)”
(1 Sam. ii. 35). Similarly we explain the phrase, “And his will
(nafsho) to trouble Israel ceased” (Judg. x. 16). Jonathan, the son of
Uzziel [in the Targum of the Prophets], did not translate this
passage, because he understood nafshi to have the first
signification, and finding, therefore, in these words sensation
ascribed to God, he omitted them from his translation. If, however,
nefesh be here taken in the last signification, the sentence can well
be explained. For in the passage which precedes, it is stated that
Providence abandoned the Israelites, and left them on the brink of
death; then they cried and prayed for help, but in vain. When,
however, they had thoroughly repented, when their misery had
increased, and their enemy had had power over them, He showed
mercy to them, and His will to continue their trouble and misery
ceased. Note it well, for it is remarkable. The preposition ba in this
passage has the force of the preposition min (“from” or “of”); and
baʻamal is identical with meʻamal. Grammarians give many instances
of this use of the preposition ba: “And that which remaineth of (ba)
the flesh and of (ba) the bread” (Lev. viii. 32); “If there remains but
few of (ba) the years” (ib. xxv. 52); “Of (ba) the strangers and of
(ba) those born in the land” (Exod. xii. 19).

[Contents]
CHAPTER XLII
Ḥai (“living”) signifies a sentient organism (lit. “growing” and “having
sensation”), comp. “Every moving thing that liveth” (Gen. ix. 3); it
also denotes recovery from a severe illness: “And was recovered (va-
yeḥi) of his sickness” (Isa. xxxviii. 9); “In the camp till they
recovered” (ḥayotam) (Josh. v. 8); “quick, raw (ḥai) flesh” (Lev. xiii.
10).

Mavet signifies “death” and “severe illness,” as in “His heart died (va-
yamot) within him, and he became as a stone” (1 Sam. xxv. 37),
that is, his illness was severe. For this reason it is stated concerning
the son of the [57]woman of Zarephath, “And his sickness was so
sore, that there was no breath left in him” (1 Kings xvii. 17). The
simple expression va-yamoth would have given the idea that he was
very ill, near death, like Nabal when he heard what had taken place.

Some of the Andalusian authors say that his breath was suspended,
so that no breathing could be perceived at all, as sometimes an
invalid is seized with a fainting fit or an attack of asphyxia, and it
cannot be discovered whether he is alive or dead; in this condition
the patient may remain a day or two.

The term ḥai has also been employed in reference to the acquisition
of wisdom. Comp. “So shall they be life (ḥayyim) unto thy soul”
(Prov. iii. 22); “For whoso findeth me findeth life” (ib. viii. 35); “For
they are life (ḥayyim) to those that find them” (ib. iv. 22). Such
instances are numerous. In accordance with this metaphor, true
principles are called life, and corrupt principles death. Thus the
Almighty says, “See, I have set before thee this day life and good
and death and evil” (Deut. xxx. 15), showing that “life” and “good,”
“death” and “evil,” are identical, and then He explains these terms.
In the same way I understand His words, “That ye may live” (ib. v.
33), in accordance with the traditional interpretation of “That it may
be well with thee” [scil. in the life to come] (ib. xxii. 7). In
consequence of the frequent use of this figure in our language our
Sages said, “The righteous even in death are called living, while the
wicked even in life are called dead.” (Talm. B. Berakhoth, p. 78).
Note this well.

[Contents]
CHAPTER XLIII
The Hebrew kanaf is a homonym; most of its meanings are
metaphorical. Its primary signification is “wing of a flying creature,”
e.g., “Any winged (kanaf) fowl that flieth in the air” (Deut. iv. 17).

The term was next applied figuratively to the wings or corners of


garments; comp. “upon the four corners (kanfoth) of thy vesture”
(ib. xxii. 12).

It was also used to denote the ends of the inhabited part of the
earth, and the corners that are most distant from our habitation.
Comp. “That it might take hold of the ends (kanfoth) of the earth”
(Job xxxviii. 13); “From the uttermost part (kenaf) of the earth have
we heard songs” (Isa. xxiv. 16).

Ibn Ganaḥ (in his Book of Hebrew Roots) says that kenaf is used in
the sense of “concealing,” in analogy with the Arabic kanaftu
alshaian, “I have hidden something,” and accordingly explains,
Isaiah xxx. 20, “And thy teacher will no longer be hidden or
concealed.” It is a good explanation, and I think that kenaf has the
same meaning in Deuteronomy xxiii. 1, “He shall not take away the
cover (kenaf) of his father”; also in, “Spread, therefore, thy cover
(kenafeka) over thine handmaid” (Ruth iii. 9). In this sense, I think,
the word is figuratively applied to God and to angels (for angels are
not corporeal, according to my opinion, as I shall explain). Ruth ii.
12 must therefore be translated “Under whose protection (kenafav)
thou art come to trust”; and wherever the word occurs in reference
to angels, it means concealment. You have surely noticed the words
of Isaiah (Isa. vi. 2), “With twain he covered his face, and with twain
he covered his feet.” Their meaning is this: The cause of his (the
angel’s) existence is hidden and concealed; this is meant by the
[58]covering of the face. The things of which he (the angel) is the
cause, and which are called “his feet” (as I stated in speaking of the
homonym regel), are likewise concealed; for the actions of the
intelligences are not seen, and their ways are, except after long
study, not understood, on account of two reasons—the one of which
is contained in their own properties, the other in ourselves; that is to
say, because our perception is imperfect and the ideals are difficult
to be fully comprehended. As regards the phrase “and with twain he
flieth,” I shall explain in a special chapter (xlix.) why flight has been
attributed to angels.

[Contents]
CHAPTER XLIV
The Hebrew ʻayin is a homonym, signifying “fountain”; e.g., “By a
fountain (ʻen) of water” (Gen. xvi. 7). It next denotes “eye”; comp.
(ʻayin) “Eye for eye” (Exod. xxi. 24). Another meaning of the word is
“providence,” as it is said concerning Jeremiah, “Take him and direct
thine attention (eneka) to him” (Jer. xxxix. 12). In this figurative
sense it is to be understood when used in reference to God; e.g.,
“And my providence and my pleasure shall be there perpetually” (1
Kings ix. 3), as we have already explained (page 140); “The eyes
(ʻene), i.e., the Providence of the Lord thy God, are always upon it”
(Deut. xi. 12); “They are the eyes (ʻene) of the Lord, which run to
and fro through the whole earth” (Zech. iv. 10), i.e., His providence
is extended over everything that is on earth, as will be explained in
the chapters in which we shall treat of Providence. When, however,
the word “eye” is connected with the verb “to see,” (raah or ḥazah)
as in “Open thine eyes, and see” (1 Kings xix. 16); “His eyes behold”
(Ps. xi. 4), the phrase denotes perception of the mind, not that of
the senses; for every sensation is a passive state, as is well known
to you, and God is active, never passive, as will be explained by me.

[Contents]
CHAPTER XLV
Shamaʻ is used homonymously. It signifies “to hear,” and also “to
obey.” As regards the first signification, comp. “Neither let it be
heard out of thy mouth” (Exod. xxiii. 13); “And the fame thereof was
heard in Pharaoh’s house” (Gen. xlv. 16). Instances of this kind are
numerous.

Equally frequent are the instances of this verb being used in the
sense of “to obey”: “And they hearkened (shameʻü) not unto Moses”
(Exod. vi. 9). “If they obey (yishmeʻü) and serve him” (Job xxxvi.
11); “Shall we then hearken (nishmaʻ) unto you” (Neh. xiii. 27);
“Whosoever will not hearken (yishmaʻ) unto thy words” (Josh. i. 18).

The verb also signifies “to know” (“to understand”), comp. “A nation
whose tongue, i.e., its language, thou shalt not understand”
(tishmaʻ) (Deut. xxviii. 49). The verb shamaʻ, used in reference to
God, must be taken in the sense of perceiving, which is part of the
third signification, whenever, according to the literal interpretation of
the passage, it appears to have the first meaning: comp. “And the
Lord heard it” (Num. xi. 1); “For that He heareth your murmurings”
(Exod. xvi. 7). In all such passages mental perception is meant.
When, however, according to the literal interpretation [59]the verb
appears to have the second signification, it implies that God
responded to the prayer of man and fulfilled his wish, or did not
respond and did not fulfil his wish: “I will surely hear his cry” (Exod.
xxii. 23); “I will hear, for I am gracious” (ib. 27); “Bow down thine
ear, and hear” (2 Kings xix. 16); “But the Lord would not hearken to
your voice, nor give ear unto you” (Deut. i. 45); “Yea, when ye make
many prayers, I will not hear” (Isa. i. 15); “For I will not hear thee”
(Jer. vii. 16). There are many instances in which shamaʻ has this
sense.

Remarks will now be presented to you on these metaphors and


similes, which will quench your thirst, and explain to you all their
meanings without leaving a doubt.

[Contents]
CHAPTER XLVI
We have already stated, in one of the chapters of this treatise, that
there is a great difference between bringing to view the existence of
a thing and demonstrating its true essence. We can lead others to
notice the existence of an object by pointing to its accidents,
actions, or even most remote relations to other objects: e.g., if you
wish to describe the king of a country to one of his subjects who
does not know him, you can give a description and an account of his
existence in many ways. You will either say to him, the tall man with
a fair complexion and grey hair is the king, thus describing him by
his accidents; or you will say, the king is the person round whom are
seen a great multitude of men on horse and on foot, and soldiers
with drawn swords, over whose head banners are waving, and
before whom trumpets are sounded; or it is the person living in the
palace in a particular region of a certain country; or it is the person
who ordered the building of that wall, or the construction of that
bridge; or by some other similar acts and things relating to him. His
existence can be demonstrated in a still more indirect way, e.g., if
you are asked whether this land has a king, you will undoubtedly
answer in the affirmative. “What proof have you?” “The fact that this
banker here, a weak and little person, stands before this large mass
of gold pieces, and that poor man, tall and strong, who stands
before him asking in vain for alms of the weight of a carob-grain, is
rebuked and is compelled to go away by the mere force of words;
for had he not feared the king, he would, without hesitation, have
killed the banker, or pushed him away and taken as much of the
money as he could.” Consequently, this is a proof that this country
has a ruler and his existence is proved by the well-regulated affairs
of the country, on account of which the king is respected and the
punishments decreed by him are feared. In this whole example
nothing is mentioned that indicated his characteristics, and his
essential properties, by virtue of which he is king. The same is the
case with the information concerning the Creator given to the
ordinary classes of men in all prophetical books and in the Law. For
it was found necessary to teach all of them that God exists, and that
He is in every respect the most perfect Being, that is to say, He
exists not only in the sense in which the earth and the heavens
exist, but He exists and possesses life, wisdom, power, activity, and
all other properties which our belief in His existence must include, as
will be shown below. That God exists was therefore shown to
ordinary [60]men by means of similes taken from physical bodies;
that He is living, by a simile taken from motion, because ordinary
men consider only the body as fully, truly, and undoubtedly existing;
that which is connected with a body but is itself not a body, although
believed to exist, has a lower degree of existence on account of its
dependence on the body for existence. That, however, which is
neither itself a body, nor a force within a body, is not existent
according to man’s first notions, and is above all excluded from the
range of imagination. In the same manner motion is considered by
the ordinary man as identical with life; what cannot move voluntarily
from place to place has no life, although motion is not part of the
definition of life, but an accident connected with it. The perception
by the senses, especially by hearing and seeing, is best known to us;
we have no idea or notion of any other mode of communication
between the soul of one person and that of another than by means
of speaking, i.e., by the sound produced by lips, tongue, and the
other organs of speech. When, therefore, we are to be informed that
God has a knowledge of things, and that communication is made by
Him to the Prophets who convey it to us, they represent Him to us
as seeing and hearing, i.e., as perceiving and knowing those things
which can be seen and heard. They represent Him to us as
speaking, i.e., that communications from Him reach the Prophets;
that is to be understood by the term “prophecy,” as will be fully
explained. God is described as working, because we do not know
any other mode of producing a thing except by direct touch. He is
said to have a soul in the sense that He is living, because all living
beings are generally supposed to have a soul; although the term
soul is, as has been shown, a homonym.

Again, since we perform all these actions only by means of corporeal


organs, we figuratively ascribe to God the organs of locomotion, as
feet, and their soles; organs of hearing, seeing, and smelling, as ear,
eye, and nose; organs and substance of speech, as mouth, tongue,
and sound; organs for the performance of work, as hand, its fingers,
its palm, and the arm. In short, these organs of the body are
figuratively ascribed to God, who is above all imperfection, to
express that He performs certain acts; and these acts are figuratively
ascribed to Him to express that He possesses certain perfections
different from those acts themselves. E.g., we say that He has eyes,
ears, hands, a mouth, a tongue, to express that He sees, hears,
acts, and speaks; but seeing and hearing are attributed to Him to
indicate simply that He perceives. You thus find in Hebrew instances
in which the perception of the one sense is named instead of the
other; thus, “See the word of the Lord” (Jer. ii. 31), in the same
meaning as “Hear the word of the Lord,” for the sense of the phrase
is, “Perceive what He says”; similarly the phrase, “See the smell of
my son” (Gen. xxvii. 27) has the same meaning as “Smell the smell
of my son,” for it relates to the perception of the smell. In the same
way are used the words, “And all the people saw the thunders and
the lightnings” (Exod. xx. 15), although the passage also contains
the description of a prophetical vision, as is well known and
understood among our people. Action and speech are likewise
figuratively applied to God, to express that a certain influence has
emanated from Him, as will be explained (chap. lxv. and chap. lxvi.).
The physical organs which are attributed to God in the writings of
the Prophets are either organs of locomotion, indicating [61]life;
organs of sensation, indicating perception; organs of touch,
indicating action; or organs of speech, indicating the divine
inspiration of the Prophets, as will be explained.

The object of all these indications is to establish in our minds the


notion of the existence of a living being, the Maker of everything,
who also possesses a knowledge of the things which He has made.
We shall explain, when we come to speak of the inadmissibility of
Divine attributes, that all these various attributes convey but one
notion, viz., that of the essence of God. The sole object of this
chapter is to explain in what sense physical organs are ascribed to
the Most Perfect Being, namely, that they are mere indications of the
actions generally performed by means of these organs. Such actions
being perfections respecting ourselves, are predicated of God,
because we wish to express that He is most perfect in every respect,
as we remarked above in explaining the Rabbinical phrase, “The
language of the Torah is like the language of man.” Instances of
organs of locomotion being applied to the Creator occur as follows:
—“My footstool” (Isa. lxvi. 1); “the place of the soles of my feet”
(Ezek. xliii. 7). For examples of organs of touch applied to God,
comp. “the hand of the Lord” (Exod. ix. 3); “with the finger of God”
(ib. xxxi. 18); “the work of thy fingers” (Ps. viii. 4), “And thou hast
laid thine hand upon me” (ib. cxxxix. 5); “The arm of the Lord” (Isa.
liii. 1); “Thy right hand, O Lord” (Exod. xv. 6). In instances like the
following, organs of speech are attributed to God: “The mouth of the
Lord has spoken” (Isa. i. 20); “And He would open His lips against
thee” (Job xi. 5); “The voice of the Lord is powerful” (Ps. xxix. 4);
“And his tongue as a devouring fire” (Isa. xxx. 27). Organs of
sensation are attributed to God in instances like the following: “His
eyes behold, His eyelids try” (Ps. xi. 4); “The eyes of the Lord which
run to and fro” (Zech. iv. 10); “Bow down thine ear unto me, and
hear” (2 Kings xix. 16); “You have kindled a fire in my nostril” (Jer.
xvii. 5). Of the inner parts of the human body only the heart is
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookgate.com

You might also like