1. Trang chủ
  2. » Công Nghệ Thông Tin

C primer plus, 5th ed 2005

2,8K 92 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 2.750
Dung lượng 11,58 MB

Nội dung

C Primer Plus, Fifth Edition By Stephen Prata Publisher : Sams Pub Date : November 23, 2004 ISBN : 0-672-32696-5 Pages : 984 Table of • Contents • Index A lean revision of a computer industry classic that has sold over 500,000 copies in previous editions Fifth Edition contains over 20 new programming exercises and newly improved examples C and C++ account for 30% of developers, about three million, and is a $22 million book market per year Updates the third edition by integrating new ANSI/ISO standard, C99 Classic that teaches the fundamentals of programming C Primer Plus, Fifth Edition By Stephen Prata Publisher : Sams Pub Date : November 23, 2004 Table of ISBN : 0-672-32696-5 • Contents Pages : 984 • Index Copyright PREFACE Approach and Goals ABOUT THE AUTHOR ACKNOWLEDGMENTS WE WANT TO HEAR FROM YOU! Chapter 1 Getting Ready Whence C? Why C? What Computers Do Using C: Seven Steps Programming Mechanics How This Book Is Organized Summary Whither C? High-level Computer Languages and Compilers Language Standards Conventions Used in This Book Review Questions Programming Exercise Chapter 2 Introducing C A Simple Example of C The Example Explained Tips on Making Your Programs Readable The Structure of a Simple Program Taking Another Step in Using C While You're at ItMultiple Functions Keywords and Reserved Identifiers Summary Introducing Debugging Key Concepts Review Questions Programming Exercises Chapter 3 Data and C A Sample Program Data Variables and Constants Basic C Data Types Arguments and Pitfalls Key Concepts Review Questions Data: Data-Type Keywords Using Data Types One More Example: Escape Sequences Summary Programming Exercises Chapter 4 Character Strings and Formatted Input/Output Introductory Program Character Strings: An Introduction Constants and the C Preprocessor Key Concepts Review Questions Exploring and Exploiting printf() and scanf() Summary Programming Exercises Chapter 5 Operators, Expressions, and Statements Introducing Loops Fundamental Operators Some Additional Operators Type Conversions A Sample Program Summary Expressions and Statements Function with Arguments Key Concepts Review Questions Programming Exercises Chapter 6 C Control Statements: Looping Revisiting the while Loop The while Statement Indefinite Loops and Counting Loops More Assignment Operators: +=, -=, *=, /=, %= An Exit-Condition Loop: do while Nested Loops A Loop Example Using a Function Return Value Summary Which Is Bigger: Using Relational Operators and Expressions The for Loop The Comma Operator Which Loop? Introducing Arrays Key Concepts Review Questions Programming Exercises Chapter 7 C Control Statements: Branching and Jumps The if Statement Adding else to the if Statement A Word-Count Program Loop Aids: continue and break The goto Statement Summary Let's Get Logical The Conditional Operator: ?: Multiple Choice: switch and break Key Concepts Review Questions Programming Exercises Chapter 8 Character Input/Output and Input Validation Single-Character I/O: getchar() and putchar() Buffers Redirection and Files Input Validation Terminating Keyboard Input Creating a Friendlier User Interface Menu Browsing Key Concepts Review Questions Summary Programming Exercises Chapter 9 Functions Reviewing Functions ANSI C Function Prototyping Recursion Finding Addresses: The & Operator Pointers: A First Look Summary Compiling Programs with Two or More Source Code Files Altering Variables in the Calling Function Key Concepts Review Questions Programming Exercises Chapter 10 Arrays and Pointers Arrays Multidimensional Arrays Functions, Arrays, and Pointers Protecting Array Contents Variable-Length Arrays (VLAs) Key Concepts Review Questions Pointers and Arrays Pointer Operations Pointers and Multidimensional Arrays Compound Literals Summary Programming Exercises Chapter 11 Character Strings and String Functions Representing Strings and String I/O String Input String Output String Functions The ctype.h Character Functions and Strings The Do-It-Yourself Option A String Example: Sorting Strings Command-Line Arguments String-to-Number Conversions Summary Key Concepts Review Questions Programming Exercises Chapter 12 Storage Classes, Linkage, and Memory Management Storage Classes Storage-Class Specifiers A Random-Number Function and a Static Variable Allocated Memory: malloc() and free() Key Concepts Review Questions Storage Classes and Functions Roll 'Em ANSI C Type Qualifiers Summary Programming Exercises Chapter 13 File Input/Output Communicating with Files Standard I/O A Simple-Minded File-Condensing Program Adventures in Random Access: fseek() and ftell() Other Standard I/O Functions Summary File I/O: fprintf(), fscanf(), fgets(), and fputs() Behind the Scenes with Standard I/O Key Concepts Review Questions Programming Exercises Chapter 14 Structures and Other Data Forms Sample Problem: Creating an Inventory of Books Setting Up the Structure Declaration Arrays of Structures Pointers to Structures Saving the Structure Contents in a File Defining a Structure Variable Nested Structures Telling Functions About Structures Structures: What Next? Unions: A Quick Look typedef: A Quick Look Functions and Pointers Summary Enumerated Types Fancy Declarations Key Concepts Review Questions Programming Exercises Chapter 15 Bit Fiddling Binary Numbers, Bits, and Bytes Other Number Bases Bit Fields Summary C's Bitwise Operators Key Concepts Review Questions Programming Exercises Chapter 16 The C Preprocessor and the C Library First Steps in Translating a Program Manifest Constants: #define Macro or Function? Other Directives The C Library The General Utilities Library memcpy() and memmove() from the string.h Library Key Concepts Review Questions Using Arguments with #define File Inclusion: #include Inline Functions The Math Library The Assert Library Variable Arguments: stdarg.h Summary Programming Exercises Chapter 17 Advanced Data Representation Exploring Data Representation Beyond the Array to the Linked List Abstract Data Types (ADTs) Simulating with a Queue Binary Search Trees Key Concepts Review Questions Getting Queued with an ADT The Linked List Versus the Array Other Directions Summary Programming Exercises Appendix A Answers to the Review Quesions Answers to Review Questions for Chapter 1 Answers to Review Questions for Chapter 2 Answers to Review Questions for Chapter 3 Answers to Review Questions for Chapter 5 Answers to Review Questions for Chapter 7 Answers to Review Questions for Chapter 9 Answers to Review Questions for Chapter 11 Answers to Review Questions for Chapter 13 Answers to Review Questions for Chapter 15 Answers to Review Questions for Chapter 4 Answers to Review Questions for Chapter 6 Answers to Review Questions for Chapter 8 Answers to Review Questions for Chapter 10 Answers to Review Questions for Chapter 12 Answers to Review Questions for Chapter 14 Answers to Review Questions for Chapter 16 Answers to Review Questions for Chapter 17 Appendix B Reference Section Section I: Additional Reading Section II: C Operators Section IV: Expressions, Statements, and Program Flow Section VI: Extended Integer Types Section VIII: C99 Numeric Computational Enhancements Section III: Basic Types and Storage Classes Section V: The Standard ANSI C Library with C99 Additions Section VII: Expanded Character Support Section IX: Differences Between C and C++ Index Copyright Copyright © 2005 by Sams Publishing All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Library of Congress Catalog Card Number: 2004095068 Printed in the United States of America First Printing: November, 2004 07 06 05 04 4 3 2 1 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Sams Publishing cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Warning and Disclaimer global.c program code initializing 2nd naming 2nd referencing declarations external linkage 2nd external variables declarations header files fathm ft.c program file scope 2nd flags floating-point declaring formal arguments formal parameters function prototype scope 2nd function scope global hiding.c program 2nd hiding.c program, code identifiers index int type declaring 2nd defining initializing 2nd internal linkage 2nd linkage 2nd 3rd external 2nd internal 2nd no 2nd local names 2nd naming 2nd _ (underscore) case sensitivity reserved identifiers no linkage 2nd num 2nd number pointers 2nd 3rd 4th & (address operator) * (asterisk) 2nd * (indirection operator) 2nd 3rd 4th communicating between functions 2nd 3rd 4th 5th constants declaring 2nd 3rd operations performed with or on variables 2nd 3rd pt ops.c program code private names qualifying comments keywords properties 2nd 3rd recursion register 2nd restrict keyword return values assigning scope 2nd 3rd 4th 5th scopes 2nd 3rd 4th 5th 6th 7th single-values static block scope 2nd 3rd 4th external linkage 2nd 3rd 4th internal linkage 2nd random number functions 2nd 3rd 4th 5th 6th 7th random number functions, automated reseeding 2nd random number functions, rand0( ) function, code random number functions, rand0.c function file program, code random number functions, rand1( ) function, code random number functions, srand1( ) function, code 2nd static storage duration 2nd storage classees storage classes 2nd 3rd 4th 5th 6th automatic 2nd 3rd 4th 5th 6th automatic storage duration 2nd 3rd 4th 5th 6th 7th 8th automatic, blocks without { } 2nd automatic, initializing 2nd external linkage 2nd external variables 2nd 3rd external variables, declaring 2nd external variables, defining 2nd external variables, defining declarations external variables, global.c program code external variables, initializing 2nd external variables, naming 2nd external variables, referencing declarations forc99.c program code 2nd internal linkage 2nd linkage 2nd no linkage 2nd register 2nd scope 2nd 3rd 4th static storage duration 2nd static, block scope 2nd 3rd 4th static, external linkage 2nd 3rd 4th static, internal linkage 2nd storage duration 2nd storage duration 2nd 3rd structure structures defining 2nd 3rd 4th initializers (designated) initializing 2nd initializing with storage class duration swapping in calling functions 2nd 3rd 4th 5th true and false unions defining values 2nd assigning program states, examining 2nd volatile keyword variadic functions variable arguments stdarg.h header file 2nd 3rd stdarg.h header file, varargs.c program code 2nd variadic macros 2nd 3rd (ellipsis) 2nd 3rd VA ARGS 2nd 3rd variadic.c program code variadic.c program (Listing 16.5) 2nd variations strncmp( ) function 2nd varwid.c program (Listing 4.16) 2nd viewpoints black box functions 2nd views binary 2nd 3rd text 2nd 3rd VLAs (variable-length arrays) 2nd 3rd 4th 5th 6th 7th dynamic memory allocation sizes vararr2d.c program code 2nd VMS programs running void (*f)(int) macros 2nd void (*signal(int sig, void (*func)(int)))(int) function void (main( ) function) void *bsearch(const void *key,const void *base, size_t nmem, size_t size, int (*comp) (const void *, function void *calloc(size_t nmem, size_t size) function void *malloc(size_t size) function void *memchr(const void *s, int c, size_t n) function void *memcpy(void * restrict s1, const void * restrict s2, size_t n) function void *memmove(void *s1, const void *s2, size_t n) function void *memset(void *s, int v, size_t n) function void *realloc(void *ptr, size_t size) function void _Exit(int status) function void abort(void) function void assert(int exprs) macro void clearerr(FILE *) function void exit(int status) function void feclearexcept(int excepts) function void fegetenv(fenv_t *envp) function void feraiseexcept(int excepts) function void fesetenv(const fenv_t *envp) function void feupdateenv(const fenv_t *envp) function void free(void *ptr) function void functions void longjmp(jmp_buf env, int val) function void perror(const char *) function void qsort(void *base, size_t nmem, size_t size, int (*comp) (const void *, const void *)) function void rewind(FILE *) function void setbuf(FILE * restrict, char * restrict) function void srand(unsigned int seed) function void statement void type functions void va_copy(va_list dest, va_list src) macro void va_end(va_list ap) macro void va_start(va_list ap, parmN) macro volatile keyword 2nd 3rd volatile type qualifier 2nd 3rd vowels.c program (Listing 7.12) 2nd 3rd [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] warnings error messages wchar.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th macros defined 2nd types defined 2nd WCHAR_MAX constant WCHAR_MAX macro WCHAR_MIN constant WCHAR_MIN macro wchar_t type 2nd 3rd wctrans_t type wctrans_t wctrans(const char *property) function wctype.h header file 2nd 3rd 4th 5th 6th macros 2nd types 2nd wctype_t type Web sites gcc compiler reference sources 2nd Sams Publishing code downloads United States Postal Service WEOF constant expression WEOF macro wheat.c program (Listing 5.5) 2nd when.c program (Listing 6.2) 2nd while keyword while keyword keywords while while loop single-character I/O values processing while loops 2nd (entry-condition loops) { } (curly braces) compound statements (blocks) 2nd 3rd conditional loops 2nd entry.c program, code 2nd relational expressions 2nd Bool type boolean.c program, code 2nd cmpflt.c program, code 2nd t and f.c program, code 2nd trouble.c program, code 2nd 3rd 4th truth.c program, code 2nd values, true and false 2nd 3rd 4th relational operators 2nd precedence 2nd shoes2.c program, code 2nd structure summing.c program 2nd 3rd reading loop 2nd summing.c program, code 2nd 3rd sweetie1.c program, code 2nd switch statements syntax points terminating 2nd 3rd when.c program, code 2nd while statement 2nd while statements 2nd while1.c program, code 2nd while2.c program, code 2nd while statement 2nd 3rd 4th 5th 6th abbreviating accessing menus entry-condition loops keywords while loops conditional loops 2nd syntax points terminating 2nd 3rd when.c program, code 2nd while1.c program, code 2nd while2.c program, code 2nd while statements 2nd while1.c program code 2nd while1.c program (Listing 6.3) while2.c program code 2nd while2.c program (Listing 6.4) 2nd whitespace test to detect text breaking into sequences whitespace characters scanf( ) function 2nd whitespaces non-whitespaces test to detect scanf( ) function wide character classification utilities wctype.h header file 2nd 3rd 4th 5th 6th wide character mapping utilities wctype.h header file 2nd 3rd 4th 5th 6th wide character support C and C++, comparing 2nd wide character utilities wchar.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th wide characters 2nd 3rd 4th 5th 6th extensible wide-character classification functions 2nd null wide wide-character transformation functions 2nd wide-character classification functions 2nd 3rd wide-character I/O functions 2nd 3rd wide-character multibyte conversion functions 2nd 3rd 4th 5th 6th 7th wide-character string utilities 2nd 3rd 4th wide-character transformation functions 2nd width.c program (Listing 4.7) 2nd widths exact width types 2nd 3rd 4th fastest minimum width types 2nd 3rd 4th 5th greatest width integer functions 2nd maximum width types 2nd 3rd minimum width types 2nd 3rd 4th 5th Windows IDEs (Integrated Development Environments) targets IDEs (Integrated Development Environments) 2nd Windows compilers functions compiling 2nd WINT_MAX constant WINT_MIN constant wint_t btowc(int c) function wint_t towctrans(wint_t wc, wctrans_t desc) function wint_t towlower(wint_t wc) function wint_t type 2nd word-count programs 2nd 3rd wordcnt.c program, code 2nd wordcnt.c program (Listing 7.7) 2nd 3rd words 2nd storing in binary search trees writing binary data to files 2nd C source code 2nd constants with int types programs 2nd text files [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] z modifier printf( ) function Zeno zeno.c program (Listing 6.14) 2nd 3rd zippo1.c program zippo1.c program (Listing 10.15) 2nd 3rd zippo2.c program (Listing 10.16) 2nd ... Numbers are stored as numbers Characters, such as the alphabetical characters you use in a text document, are stored as numbers; each character has a numeric code The instructions that a computer loads into its registers are stored... Loretta Yates MANAGING EDITOR Charlotte Clapp DEVELOPMENT EDITOR Songlin Qiu PROJECT EDITOR George E Nedeff COPY EDITOR Bart Reed INDEXER Chris Barrick PROOFREADER Paula Lowell TECHNICAL EDITOR Greg Perry... instructions that a computer loads into its registers are stored as numbers; each instruction in the instruction set has a numeric code Second, computer programs ultimately have to be expressed in this numeric instruction code, or what is called machine language

Ngày đăng: 19/04/2019, 15:53

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN