Front cover image for A book on C : programming in C

A book on C : programming in C

Serves as a tutorial and reference on the ANSI C programming language. This book includes information on transitioning to Java and C++ from C. Step-by-step dissections of program code illuminate the correct usage and syntax of C language constructs and reveal the underlying logic of their application.
eBook, English, ©1998
Addison-Wesley, Reading, Mass., ©1998
1 online resource (xxi, 726 pages) : illustrations
654471464
( Each chapter concludes with a Summary and Exercises.) Preface. Starting from Zero. Why C? ANSI C Standard. From C to C++. From C and C++ to Java. 1. An Overview of C. Programming and Preparation. Program Output. Variables, Expressions, and Assignment. The Use of #define and #include. The Use of printf() and scanf(). Flow of Control. Functions. Call-by-Value. Arrays, Strings, and Pointers. Arrays. Strings. Pointers. Files. Operating System Considerations. Writing and Running a C Program. Interrupting a Program. Typing an End-of-file Signal. Redirection of the Input and the Output. 2. Lexical Elements, Operators, and the C System. Characters and Lexical Elements. Syntax Rules. Comments. Keywords. Identifiers. Constants. String Constants. Operators and Punctuators. Precedence and Associativity of Operators. Increment and Decrement Operators. Assignment Operators. An Example: Computing Powers of 2. The C System. The Preprocessor. The Standard Library. 3. The Fundamental Data Types. Declarations, Expressions, and Assignment. The Fundamental Data Types. Characters and the Data Type char. The Data Type int. The Integral Types short, long, and unsigned. The Floating Types. The Use of typedef. The sizeof Operator. The Use of getchar() and putchar(). Mathematical Functions. The Use of abs() and fabs(). UNIX and the Mathematics Library. Conversions and Casts. The Integral Promotions. The Usual Arithmetic Conversions. Casts. Hexadecimal and Octal Constants. 4. Flow of Control. Relational, Equality, and Logical Operators. Relational Operators and Expressions. Equality Operators and Expressions. Logical Operators and Expressions. Short-circuit Evaluation. The Compound Statement. The Expression and Empty Statement. The if and the if-else Statements. The while Statement. The for Statement. An Example: Boolean Variables. The Comma Operator. The do Statement. An Example: Fibonacci Numbers. The goto Statement. The break and continue Statements. The switch Statement. The Conditional Operator. 5. Functions. Function Definition. The return Statement. Function Prototypes. Function Prototypes in C++. An Example: Creating a Table of Powers. Function Declarations from the Compiler’s Viewpoint. Limitations. An Alternate Style for Function Definition Order. Function Invocation and Call-by-Value. Developing a Large Program. What Constitutes a Large Program? Using Assertions. Scope Rules. Parallel and Nested Blocks. Using a Block for Debugging. Storage Classes. The Storage Class auto. The Storage Class extern. The Storage Class register. The Storage Class static. Static External Variables. Default Initialization. Recursion. Efficiency Considerations. An Example: The Towers of Hanoi. 6. Arrays, Pointers, and Strings. One-dimensional Arrays. Initialization. Subscripting. Pointers. Call-by-Reference. The Relationship Between Arrays and Pointers. Pointer Arithmetic and Element Size. Arrays as Function Arguments. An Example: Bubble Sort. Dynamic Memory Allocation With calloc() and malloc(). Offsetting the Pointer. An Example: Merge and Merge Sort. Strings. String-Handling Functions in the Standard Library. Multidimensional Arrays. Two-dimensional Arrays. The Storage Mapping Function. Formal Parameter Declarations. Three-dimensional Arrays. Initialization. The Use of typedef. Arrays of Pointers. Arguments to main(). Ragged Arrays. Functions as Arguments. Functions as Formal Parameters in Function Prototypes. An Example: Using Bisection to Find the Root of a Function. The Kepler Equation. Arrays of Pointers to Function. The Type Qualifiers const and volatile. 7. Bitwise Operators and Enumeration Types. Bitwise Operators and Expressions. Bitwise Complement. Two’s Complement. Bitwise Binary Logical Operators. Left and Right Shift Operators. Masks. Software Tools: Printing an int Bitwise. Packing and Unpacking. Multibyte Character Constants. Enumeration Types. An Example: The Game of Paper, Rock, Scissors. 8. The Preprocessor. The Use of #include. The Use of #define. Syntactic Sugar. Macros with Arguments. The Type Definitions and Macros in stddef.h. An Example: Sorting with qsort(). An Example: Macros with Arguments. The Macros in stdio.h and ctype.h. Conditional Compilation. The Predefined Macros. The Operators # and ##. The assert() Macro. The Use of #error and #pragma. Line Numbers. Corresponding Functions. An Example: Quicksort. 9. Structures and Unions. Structures. Accessing Members of a Structure. Operator Precedence and Associativity: A Final Look. Using Structures with Functions. Initialization of Structures. An Example: Playing Poker. Unions. Bit Fields. An Example: Accessing Bits and Bytes. The ADT Stack. 10. Structures and List Processing. Self-referential Structures. Linear Linked Lists. Storage Allocation. List Operations. Some List Processing Functions. Insertion. Deletion. Stacks. An Example: Polish Notation and Stack Evaluation. Queues. Binary Trees. Binary Tree Traversal. Creating Trees. General Linked Lists. Traversal. The Use of calloc() and Building Trees. 11. Input/Output and the Operating System. The Output Function printf(). The Input Function scanf(). The Functions fprintf(), fscanf(), sprintf(), and sscanf(). The Functions fopen() and fclose(). An Example: Double Spacing a File. Using Temporary Files and Graceful Functions. Accessing a File Randomly. File Descriptor Input/Output. File Access Permissions. Executing Commands from Within a C Program. Using Pipes from Within a C Program. Environment Variables. The C Compiler. Using the Profiler. Libraries. How to Time C Code. The Use of make. The Use of touch. Other Useful Tools. 12. Advanced Applications. Creating a Concurrent Process with fork(). Overlaying a Process: the exec...() Family. Using the spawn...() Family. Interprocess Communication Using pipe(). Signals. An Example: The Dining Philosophers. Dynamic Allocation of Matrices. Why Arrays of Arrays Are Inadequate. Building Matrices with Arrays of Pointers. Adjusting the Subscript Range. Allocating All the Memory at Once. Returning the Status. 13. Moving from C to C++. Output. Input. Functions. Classes and Abstract Data Types. Overloading. Constructors and Destructors. Object-oriented Programming and Inheritance. Polymorphism. Templates. C++ Exceptions. Benefits of Object-oriented Programming. 14. Moving from C to Java. Output. Variables and Types. Classes and Abstract Data Types. Overloading. Construction and Destruction of Class Types. Object-oriented Programming and Inheritance. Polymorphism and Overriding Methods. Applets. Java Exceptions. Benefits of Java and OOP. Appendix A. The Standard Library. Diagnostics. Character Handling. Testing a Character. Mapping a Character. Errors. Floating Limits. Integral Limits. Localization. Mathematics. Nonlocal Jumps. Signal Handling. Variable Arguments. Common Definitions. Input/Output. Opening, Closing, and Conditioning a File. Accessing the File Position Indicator. Error Handling. Character Input/Output. Formatted Input/Output. Direct Input/Output. Removing or Renaming a File. A.13 General Utilities. Dynamic Allocation of Memory. Searching and Sorting. Pseudo Random-Number Generator. Communicating with the Environment. Integer Arithmetic. String Conversion. Multibyte Character Functions. Multibyte String Functions. Leaving the Program. Memory and String Handling. Memory-Handling Functions. String-Handling Functions. Date and Time. Accessing the Clock. Accessing the Time. Miscellaneous. File Access. Using File Descriptors. Creating a Concurrent Process. Overlaying a Process. Interprocess Communication. Suspending Program Execution. Appendix B. Language Syntax. Program. Function Definition. Declaration. Statement. Expression. Constant. String Literal. Preprocessor. Appendix C. ANSI C Compared to Traditional C. Types. Constants. Declarations. Initializations. Expressions. Functions. Conversions. Array Pointers. Structures and Unions. Preprocessor. Header Files. Miscellaneous. Appendix D. ASCII Character Codes. Appendix E Operator Precedence and Associativity. Index. 0201183994T04062001
Includes index