内容简介
Contents At a Glance
1 Introduction
2 Some Fundamentals
3 Compiling and RunningYour First Program
4 Variables, Data Types, and Arithmetic Expressions
5 Program Looping
6 Making Decisions
7 Working with Arrays
8 Working with Functions
9 Working with Structures
10 Character Strings
11 Pointers
12 Operations on Bits
13 The Preprocessor
14 More on Data Types
15 Working with Larger Programs
16 Input and Output Operations in C
17 Miscellaneous and Advanced Features
18 Debugging Programs
19 Object-Oriented Programming
A C Language Summary
B The Standard C Library
C Compiling Programs with gcc
D Common Programming Mistakes
E Resources
Index
Table of Contents
1 Introduction
2 Some Fundamentals
Programming
Higher-Level Languages
Operating Systems
Compiling Programs
Integrated Development Environments
Language Interpreters
3 Compiling and Running Your First Program
CompilingYour Program
RunningYour Program
UnderstandingYour First Program
Displaying the Values of Variables
Comments
Exercises
4 Variables, Data Types, and ArithmeticExpressions
Working with Variables
Understanding Data Types and Constants
The Basic Integer Type int
The Floating NumberType float
The Extended Precision Type double
The Single Character Type char
The Boolean Data Type_Bool
Type Specifiers: long, long long, short, unsigned, and signed
Working with Arithmetic Expressions
Integer Arithmetic and the Unary Minus Operator
The Modulus Operator
Integer and Floating-Point Conversions
Combining Operations with Assignment: The Assignment Operators
Types_Complex and_Imaginary
Exercises
5 Program Looping
The for Statement
Relational Operators
Aligning Output
Program Input
Nested for Loops
for Loop Variants
The while Statement
The do Statement
The break Statement
The continue Statement
Exercises
6 Making Decisions
The if Statement
The if-else Construct
Compound Relational Tests
Nested if Statements
The else if Construct
The switch Statement
Boolean Variables
The Conditional Operator
Exercises
7 Working with Arrays
Defining an Array
Using Array Elements as Counters
Generating Fibonacci Numbers
Using an Array to Generate Prime Numbers
Initializing Arrays
Character Arrays
Base Conversion Using Arrays
The const Qualifier
Multidimensional Arrays
Variable-Length Arrays
Exercises
8 Working with Functions
Defining a Function
Arguments and LocalVariables
Function Prototype Declaration
Automatic LocalVariables
Returning Function Results
Functions Calling Functions Calling...
Declaring Return Types and Argument Types
Checking Function Arguments
Top-Down Programming
Functions and Arrays
Assignment Operators
Sorting Arrays
Multidimensional Arrays
GlobalVariables
Automatic and Static Variables
Recursive Functions
Exercises
9 Working with Structures
A Structure for Storing the Date
Using Structures in Expressions
Functions and Structures
A Structure for Storing theTime
Initializing Structures
Compound Literals
Arrays of Structures
Structures Containing Structures
Structures Containing Arrays
Structure Variants
Exercises
10 Character Strings
Arrays of Characters
Variable-Length Character Strings
Initializing and Displaying Character Strings
TestingTwo Character Strings for Equality
Inputting Character Strings
Single-Character Input
The Null String
Escape Characters
More on Constant Strings
Character Strings, Structures, and Arrays
A Better Search Method
Character Operations
Exercises
11 Pointers
Defining a PointerVariable
Using Pointers in Expressions
Working with Pointers and Structures
Structures Containing Pointers
Linked Lists
The Keyword const and Pointers
Pointers and Functions
Pointers and Arrays
A Slight Digression About Program Optimization
Is It an Array or Is It a Pointer?
Pointers to Character Strings
Constant Character Strings and Pointers
The Increment and Decrement Operators Revisited
Operations on Pointers
Pointers to Functions
Pointers and Memory Addresses
Exercises
12 Operations on Bits
Bit Operators
The Bitwise AND Operator
The Bitwise Inclusive-OR Operator
The Bitwise Exclusive-OR Operator
The Ones Complement Operator
The Left Shift Operator
The Right Shift Operator
A Shift Function
Rotating Bits
Bit Fields
Exercises
13 The Preprocessor
The #define Statement
Program Extendability
Program Portability
More Advanced Types of Definitions
The # Operator
The ## Operator
The #include Statement
System Include Files
Conditional Compilation
The #ifdef, #endif, #else, and #ifndef Statements
The #if and #elif Preprocessor Statements
The #undef Statement
Exercises
14 More on Data Types
Enumerated Data Types
The typedef Statement
Data Type Conversions
Sign Extension
Argument Conversion
Exercises
15 Working with Larger Programs
DividingYour Program into Multiple Files
Compiling Multiple Source Files from the Command Line
Communication Between Modules
External Variables
Static Versus Extern Variables and Functions
Using Header Files Effectively
Other Utilities for Working with Larger Programs
The make Utility
The cvs Utility
Unix Utilities: ar, grep, sed, and so on
16 Input and Output Operations in C
Character I/O: getchar and putchar
Formatted I/O: printf and scanf
The printf Function
The scanf Function
Input and Output Operations with Files
Redirecting I/O to a File
End of File
Special Functions for Working with Files
The fopen Function
The getc and putc Functions
The fclose Function
The feof Function
The fprintf and fscanf Functions
The fgets and fputs Functions
stdin, stdout, and stderr
The exit Function
Renaming and Removing Files
Exercises
17 Miscellaneous and Advanced Features
Miscellaneous Language Statements
The goto Statement
The null Statement
Working with Unions
The Comma Operator
Type Qualifiers
The register Qualifier
The volatile Qualifier
The restrict Qualifier
Command-Line Arguments
Dynamic Memory Allocation
The calloc and malloc Functions
The sizeof Operator
The free Function
18 Debugging Programs
Debugging with the Preprocessor
Debugging Programs with gdb
Working with Variables
Source File Display
Controlling Program Execution
Getting a Stack Trace
Calling Functions and Setting Arrays and Structures
Getting Help with gdb Commands
Odds and Ends
19 Object-Oriented Programming
What Is an Object Anyway?
Instances and Methods
Writing a C Program toWork with Fractions
Defining an Objective-C Class to Work with Fractions
Defining a C++ Class toWork with Fractions
Defining a C# Class to Work with Fractions
A C Language Summary
1.0 Digraphs and Identifiers
1.1 Digraph Characters
1.2 Identifiers
2.0 Comments
3.0 Constants
3.1 Integer Constants
3.2 Floating-Point Constants
3.3 Character Constants
3.4 Character String Constants
3.5 Enumeration Constants
4.0 Data Types and Declarations
4.1 Declarations
4.2 Basic Data Types
4.3 Derived DataTypes
4.4 Enumerated Data Types
4.5 The typedef Statement
4.6 Type Modifiers const, volatile, and restrict
5.0 Expressions
5. 1 Summary of C Operators
5.2 Constant Expressions
5.3 Arithmetic Operators
5.4 Logical Operators
5.5 Relational Operators
5.6 Bitwise Operators
5.7 Increment and Decrement Operators
5.8 Assignment Operators
5.9 Conditional Operators
5.10 Type Cast Operator
5.11 sizeof Operator
5.12 Comma Operator
5.13 Basic Operations with Arrays
5.14 Basic Operations with Structures
5.15 Basic Operations with Pointers
5.16 Compound Literals
5.17 Conversion of Basic Data Types
6.0 Storage Classes and Scope
6.1 Functions
6.2 Variables
7.0 Functions
7.1 Function Definition
7.2 Function Call
7.3 Function Pointers
8.0 Statements
8.1 Compound Statements
8.2 The break Statement
8.3 The continue Statement
8.4 The do Statement
8.5 The for Statement
8.6The goto Statement
8.7 The if Statement
8.8 The null Statement
8.9 The return Statement
8.10The switch Statement
8.11 The while Statement
9.0 The Preprocessor
9.1 Trigraph Sequences
9.2 Preprocessor Directives
9.3 Predefined Identifiers
B The Standard C Library
Standard Header Files
<stddef. h>
<limits.h>
<stdbool. h>
<float.h>
<stdint .h>
String Functions
Memory Functions
Character Functions
I/O Functions
In-Memory Format Conversion Functions
String-to-Number Conversion
Dynamic Memory Allocation Functions
Math Functions
Complex Arithmetic
General Utility Functions
C Compiling Programs with gcc
General Command Format
Command-Line Options
D Common Programming Mistakes
E Resources
Answers to Exercises, Errata, etc
The C Programming Language
Books
Web Sites
Newsgroups
C Compilers and Integrated Development Environments
gcc
MinGW
CygWin
Visual Studio
CodeWarrior
Kylix
Miscellaneous
Object-Oriented Programming
The C+++ Language
The C# Language
The Objective-C Language
Development Tools
Index