ebook img

C Primer Plus, 6th Edition PDF

1067 Pages·2013·6.88 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview C Primer Plus, 6th Edition

ptg11524036 C Primer Plus Sixth Edition ptg11524036 Developer’s Library ESSENTIAL REFERENCES FOR PROGRAMMING PROFESSIONALS Developer’s Library books are designed to provide practicing programmers with unique, high-quality references and tutorials on the programming languages and technologies they use in their daily work. All books in the Developer’s Library are written by expert technology practitioners who are especially skilled at organizing and presenting information in a way that’s useful for other programmers. Key titles include some of the best, most widely acclaimed books within their topic areas: PHP & MySQL Web Development Python Essential Reference Luke Welling & Laura Thomson David Beazley ISBN 978-0-672-32916-6 ISBN-13: 978-0-672-32978-4 MySQL PostgreSQL ptg11524036 Paul DuBois Korry Douglas ISBN-13: 978-0-321-83387-7 ISBN-13: 978-0-672-32756-8 Linux Kernel Development C++ Primer Plus Robert Love Stephen Prata ISBN-13: 978-0-672-32946-3 ISBN-13: 978-0-321-77640-2 Developer’s Library books are available in print and in electronic formats at most retail and online bookstores, as well as by subscription from Safari Books Online at safari. informit.com Developer’s Library informit.com/devlibrary C Primer Plus Sixth Edition ptg11524036 Stephen Prata Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City C Primer Plus Acquisitions Editor Sixth Edition Mark Taber Copyright © 2014 by Pearson Education, Inc. Managing Editor Sandra Schroeder 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 Project Editor otherwise, without written permission from the publisher. No patent liability is assumed Mandie Frank with respect to the use of the information contained herein. Although every precaution Copy Editor has been taken in the preparation of this book, the publisher and author assume no Geneil Breeze responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. Indexer Johnna VanHoose ISBN-13: 978-0-321-92842-9 Dinse ISBN-10: 0-321-92842-3 Proofreader Jess DeGabriele Library of Congress Control Number: 2013953007 Technical Editor Danny Kalev Printed in the United States of America Publishing First Printing: December 2013 Coordinator Vanessa Evans Trademarks Designer All terms mentioned in this book that are known to be trademarks or service marks have Chuti Prasertsith been appropriately capitalized. Pearson 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 Page Layout trademark or service mark. Jake McFarland Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. ptg11524036 Bulk Sales Pearson offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales [email protected] Contents at a Glance Preface xxvii 1 Getting Ready 1 2 Introducing C 27 3 Data and C 55 4 Character Strings and Formatted Input/Output 99 5 Operators, Expressions, and Statements 143 6 C Control Statements: Looping 189 7 C Control Statements: Branching and Jumps 245 8 Character Input/Output and Input Validation 299 9 Functions 335 10 Arrays and Pointers 383 11 Character Strings and String Functions 441 12 Storage Classes, Linkage, and Memory Management 511 ptg11524036 13 File Input/Output 565 14 Structures and Other Data Forms 601 15 Bit Fiddling 673 16 The C Preprocessor and the C Library 711 17 Advanced Data Representation 773 Appendixes A Answers to the Review Questions 861 B Reference Section 905 Index 1005 Table of Contents Preface xxvii 1 Getting Ready 1 Whence C? 1 Why C? 2 Design Features 2 Efficiency 3 Portability 3 Power and Flexibility 3 Programmer Oriented 3 Shortcomings 4 Whither C? 4 What Computers Do 5 High-level Computer Languages and Compilers 6 Language Standards 7 The First ANSI/ISO C Standard 8 ptg11524036 The C99 Standard 8 The C11 Standard 9 Using C: Seven Steps 9 Step 1: Define the Program Objectives 10 Step 2: Design the Program 10 Step 3: Write the Code 11 Step 4: Compile 11 Step 5: Run the Program 12 Step 6: Test and Debug the Program 12 Step 7: Maintain and Modify the Program 13 Commentary 13 Programming Mechanics 13 Object Code Files, Executable Files, and Libraries 14 Unix System 16 The GNU Compiler Collection and the LLVM Project 18 Linux Systems 18 Command-Line Compilers for the PC 19 Integrated Development Environments (Windows) 19 The Windows/Linux Option 21 C on the Macintosh 21 How This Book Is Organized 22 Conventions Used in This Book 22 Typeface 22 Program Output 23 Special Elements 24 Summary 24 Review Questions 25 Programming Exercise 25 2 Introducing C 27 A Simple Example of C 27 The Example Explained 28 Pass 1: Quick Synopsis 30 Pass 2: Program Details 31 The Structure of a Simple Program 40 Tips on Making Your Programs Readable 41 Taking Another Step in Using C 42 Documentation 43 ptg11524036 Multiple Declarations 43 Multiplication 43 Printing Multiple Values 43 While You’re at It—Multiple Functions 44 Introducing Debugging 46 Syntax Errors 46 Semantic Errors 47 Program State 49 Keywords and Reserved Identifiers 49 Key Concepts 50 Summary 51 Review Questions 51 Programming Exercises 53 3 Data and C 55 A Sample Program 55 What’s New in This Program? 57 Data Variables and Constants 59 Data: Data-Type Keywords 59 Integer Versus Floating-Point Types 60 viii Contents The Integer 61 The Floating-Point Number 61 Basic C Data Types 62 The int Type 62 Other Integer Types 66 Using Characters: Type char 71 The _Bool Type 77 Portable Types: stdint.h and inttypes.h 77 Types float, double, and long double 79 Complex and Imaginary Types 85 Beyond the Basic Types 85 Type Sizes 87 Using Data Types 88 Arguments and Pitfalls 89 One More Example: Escape Sequences 91 What Happens When the Program Runs 91 Flushing the Output 92 Key Concepts 93 ptg11524036 Summary 93 Review Questions 94 Programming Exercises 97 4 Character Strings and Formatted Input/Output 99 Introductory Program 99 Character Strings: An Introduction 101 Type char Arrays and the Null Character 101 Using Strings 102 The strlen() Function 103 Constants and the C Preprocessor 106 The const Modifier 109 Manifest Constants on the Job 109 Exploring and Exploiting printf() and scanf() 112 The printf() Function 112 Using printf() 113 Conversion Specification Modifiers for printf() 115 What Does a Conversion Specification Convert? 122 Using scanf() 128 Contents ix The * Modifier with printf() and scanf() 133 Usage Tips for printf() 135 Key Concepts 136 Summary 137 Review Questions 138 Programming Exercises 140 5 Operators, Expressions, and Statements 143 Introducing Loops 144 Fundamental Operators 146 Assignment Operator: = 146 Addition Operator: + 149 Subtraction Operator: – 149 Sign Operators: – and + 150 Multiplication Operator: * 151 Division Operator: / 153 Operator Precedence 154 Precedence and the Order of Evaluation 156 ptg11524036 Some Additional Operators 157 The sizeof Operator and the size_t Type 158 Modulus Operator: % 159 Increment and Decrement Operators: ++ and -- 160 Decrementing: -- 164 Precedence 165 Don’t Be Too Clever 166 Expressions and Statements 167 Expressions 167 Statements 168 Compound Statements (Blocks) 171 Type Conversions 174 The Cast Operator 176 Function with Arguments 177 A Sample Program 180 Key Concepts 182 Summary 182 Review Questions 183 Programming Exercises 187

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.