Deitel@ Series Page How To Program Series C How to Program, 6/E C++ how to Program, 7/E Java how to Program, 8/E, Early Objects Version Java How to Program, 8/E, Late Objects Version Internet World Wide Web how to program, 4/E Visual basic( 2008 How to program Visual C# 2008 How to Program, 3/E Visual C++@ 2008 How to Program, 2/E Small Java How to Program, 6/E Small C++ how to Program, 5/E Simply Series Simply C++: An Application-Driven Simply c#: An application-Driven Tutorial Approach Tutorial Ar P proach Simply Java Programming: An Simply visual Basic 2008, 3/E: An Application-Driven Tutorial Application-Driven Tutorial Approach pproach CourseSmart Web Books Www.dEitel.com/books/coursesmart.htmi C++ how to Program, 5/E, 6/E &7/e Small C++ How to Program, 5/E Java How to Program, 6/E, 7/E &8/E Small Java How to Program, 6/E Simply C++: An Application-Driven Visual Basic( 2008 How to Program Tutorial Approach Visual C#@ 2008 How to Program, 3/E Simply visual basic 2008: An Application-Driven Tutorial Approach, 3/E Deitel Developer Series AJAX, Rich Internet Applications and iPhone for Progr rammers Web Development for Programmers An App-Driven Approach C++ for programmers ava for programmers C# 2008 for Programmers, 3/E Javascript for Programmers LiveLessons Video Learning Products Www.dEitel.com/books/livelessons/ Java Fundamentals parts 1 and 2 C++ Fundamentals parts 1 and 2 C# Fundamentals parts 1 and 2 Java Script Fundamentals Parts 1 and 2 To receive updates on Deitel publications, Resource Centers, training courses,partner offers and more, please register for the free deitel Buzz Online e-mail newsletter at Www.dEiteL.com/newsletter/subscribe.html follow us on Twitter adeste and facebook@e /wdeitel. com/dei tel fan/ To communicate with the authors, send e-mail to deitel adeitel com For information on government and corporate Dive-IntoB Series on-site seminars offered by Deitel Associates, Inc. worldwide, visi Www.dEitel.com/training/ or write to deitel adeitel, com For continuing updates on prentice Hall/Deitel publications visit www.deitel.com Www.Pearsonhighered.com/deitel Check out our Resource Centers for valuable web resources that will help yo ou master Java, other important programming languages, software and Internet-and web-related topICS Www.dEiteL.com/resourcecenteRs.html orary of Congress Cataloging-in-Publication Data On file Vice President and Editorial Director, ECS: Marcia horton Editor-in-Chief, Computer Science: Michael hirsch Associate Editor: Carole snyder Supervisor/Editorial Assistant: Dolores Mars Director of Team-Based Project Management: Vince O'Brien Senior Managing Editor: Scott Disanno Managing Editor: Robert Engelhardt A/V Production Editor: Greg dulles Art Director: Kristine Carney Cover Design: Abbey S. Deitel Harvey M. Deitel, Francesco Santalucia, Kristine Carney Interior Design: Harvey M. Deitel, Kristine Carney Manufacturing Manager: Alexis Heydt-Long Manufacturing buyer: Lisa McDowell Director of Marketing: Margaret Waple Marketing m Erin davis PEARSON o 2010 by Pearson Education, Inc Prentice ian Upper Saddle riv Iver. y07458 The authors and publisher of this book have used their best efforts in preparing this book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and pub lisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in this book. The authors and publisher shall not be liable in any event for incidental or consequential dam- ages in connection with, or arising out of, the furnishing, performance, or use of these programs Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks and registered trademarks. Where those designations appear in this book, and Prentice Hall and the authors were aware of a trademark claim, the designations have been printed in initial caps or all caps. All product names mentioned remain trademarks or registered trademarks of their respective owners All rights reserved. No part of this book may be reproduced, in any form or by any means, without permission writing from the publishe Printed in the United States of America 10987654321 工SBN-10:0-13-612356-2 工SBN-13:978-0-13-612356-9 Pearson Education Ltd, London Pearson Education Australia Pty. Ltd, Sydney Pearson Education Singapore, Pte. Ltd Pearson Education North Asia Ltd, Hong Kong Pearson Education Canada, Inc. Toronto Pearson educacion de mexico, S.A. de C. v Pearson Education-Japan, Tokyo Pearson Education Malaysia, Pte Ltd Pearson Education, Inc, Upper Saddle river, New Jersey C TM HoWT○ PROGRAM SIXTH EDITION P。. Deitel Deitel d associates, Inc H.M。 Deite Deitel e associates, Inc PEARSON Preeti Hall DEITEL Upper Saddle river, New Jersey 07458 Trademarks DEITEL, the double-thumbs-up bug and DiVE INTO are registered trademarks of Deitel and associates Microsoft, Visual C++, Internet Explorer and the Windows logo are either registered trademarks or trade marks of microsoft Corporation in the United States and/or other countries In memory of clifford Stephens four friendship, bright smile and infectious laugh will be truly missed. Paul and harvey Deitel Deitel resource Centers Our resource Centers focus on the vast amounts of free content available online. Find resources downloads, tutorials, documentation, books, e-books, journals, articles, blogs, rss feeds and more on many of today's hottest programming and technology topics. For the most up-to-date list of our Resource centers, visit Www.Deitel.com/resourcecenterS.html Let us know what other Resource Centers you'd like to see! Also, please register for the free Deite/ Buzz online e-mail newsletter at /wwdeitel. com/newsletter/subscribe htmI Computer Science UML Java design patterns Functional Programming Visual basic Java ee 5 Search engines Regular expressions Visual c++ Java se 6 Visual Studio Team Sys Java SE 7(Dolphin) Programming tem Resource center Web Servers Web 3D Technologies JavaFX Wikis Adobe flex Web Services Windows vista Windows Presentation Microsoft A Foundation ASPNET Web 2.0 ASPNET Ajax XHTML ASP.nET 3.5 Alert Services ASPNet XML ASP.NET Ajax Attention Economy C# Ap Blogging 十十 DotNetNuke ( dnn) Building Web C++ boost libraries iPhone Internet Explorer 7(IE Communities C++ Game Programming Objective-C Microsoft lino Community generated C# Cocoa NET Code Search Engines and Games and game neT 3.0 Facebook develop Code sites nEt 3.5 atform omputer Game Programming Sharepoint Facebook Social Ads P omputer Game Pro- Silverlight Ing Google base CSS 2.1 gramming Visual b Google video Dojo Computer Ga ames Visual ct+ Mobile Gaming Google Web To Facebook developer plat- Visual studio team (GWT Sudoku nternet video Flash 9 Internet business Windows prese Functional pros ramming Affiliate Programs Location-Based Services Windows vista Mashups Competitive analysis Java Certification and Microsoft popfly Microformats Facebook Social ads Assessment Testing ogle Ads Recommender Systems Open source Java Design Patterns Java ee 5 GGG LAMP Stack Social graph Java Se 6 Apach eala Java Se 7(Dolphin) Internet Advertising Internet business DotNetNuke(dnn) Social Networking Resource center Eclipse Software as a service Initiative JavaFX Firefox Internet Public relations JavaScript InuX V irtual Worlds JSON Link Building lySQL Web 2.0 Location-Based services Microsoft linQ Open source Web 3.0 Online lead generation Microsoft popfly Perl Widgets Podcasting PHP Search Engine Optimiza NeT 3.0 vtho Dive into Web 2.0 tion Rub Selling Digital Content Opengl Site Soft Web 2 eBook Perl PHP Web analytic apache Other Topics Website monetization Programming Projects DotNetNuke dnn) You Tube and AdSense Computer games clipse Job egular Expressions ava Gadgets and gizmos Rub Internet Explorer 7(IE Ring to y Ruby on rails Linux Java Certification and Sudoku enlight Assessment Testing MySQL Contents Appendices E through I are PDF documents posted online at the books Companion Website(locatedatwww.pearsonhighered.com/deitel) Preface XXI I Introduction to Computers, the Internet and the web 1.1 Introduction 1.2 Computers: Hardware and Software 1.3 Computer organization 4 1.4 Personal, Distributed and Client/Server Computing 1. 5 The Internet and the World Wide Web 1.6 Machine Languages, Assembly Languages and High-Level languages 1.7 History of C 1. 8 C Standard Library 8 1.9 十 1.10 Java 1.11 Fortran. COBOL, Pascal and ada 10 1.12 BASIC, Visual Basic, Visual C++, C# and. NEt 10 1.13 Key Software Trend: Object Technology 1.14 Typical C Program Development Environment 12 1. 15 Hardware Trends 14 1.16 Notes about C and This book 1.17 Web Resources 16 2 Introduction to C Programming 23 2.1 Introduction 24 2.2 A Simple c program: Printing a Line of Text 24 2.3 Another Simple C Program: Adding Two Integers 28 2.4 Memory Concepts 33 2.5 Arithmetic in C 34 2.6 Decision Making: Equality and relational Operators 38 3 Structured Program Development in C 54 3.1 Introduction 3.2 Algorithms 55