Beginning Programming with C For Dummies Published by John Wiley & Sons, Inc. 111 River StreetHoboken, NJ 07030-5774 www.wiley.com Copyright 2014 by John Wiley & Sons, Inc., Hoboken, New Jersey Published by John Wiley & Sons, Inc., Hoboken, New Jersey Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions . Trademarks: Wiley, the Wiley logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners.
John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought.
Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.
For technical support, please visit www.wiley.com/techsupport . Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Not all content that is available in standard print versions of this book may appear or be packaged in all book formats. If you have purchased a version of this book that did not include media that is referenced by or accompanies a standard print version, you may request this media by visiting http://booksupport.wiley.com . For more information about Wiley products, visit us at www.wiley.com . Library of Congress Control Number: 2013948031 ISBN 978-1-118-73763-7 (pbk); ISBN 978-1-118-73765-1 (ebk); ISBN 978-1-118-73762-0 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Introduction S ay Hello, world to Beginning Programming with C For Dummies , a book that transforms you from a well-meaning, caring human being into an admired element of the underground nerd subculture, the programmer.
Oh, yes, thats a good thing. When you learn to code in C, you become the ultimate master of a number of electronic gizmos. You can craft your own programs, dictating to computers, tablets, and cell phones your very whims and desires. And the electronics dutifully obey. Given the information offered in this book, you can pass that programming class, impress your friends, be admired by Hollywood, or even start your own software company. Yes, learning to program is a worthy investment of your time.
This book helps make learning how to program understandable and enjoyable. You dont need any programming experience you dont even need to buy new software. You just need the desire to program in C and the ability to have fun while doing so. Is the C Language Relevant? An argument surfaces every few years that learning C is a road to nowhere. Newer, better programming languages exist, and its far better to learn them than to waste time learning C. Poppycock.
In a way, C is the Latin of computer languages. Just about every Johnny-come-lately programming language uses C syntax. C keywords and even certain functions find their way into other popular languages, from C++ to Java to Python to whatever the latest, trendy language could be. My point is that once you learn C programming, all those other programming languages come easy. In fact, many of the books that teach those other languages often assume that you know a little C before you start out. That can be frustrating for any beginner but not when you already know C.
Despite what the pundits and poobahs say, C is still relevant. Programming for microcontrollers, operating systems, and major software packages is still done using good ol C. You are not wasting your time. The C Programming For Dummies Approach As a programmer, Ive toiled through many, many programming books. I know what I really dont like to see, and, lamentably, I see it often that is, where the author writes pages-long code or simply boasts about what he knows, impressing his fellow nerds and not really teaching anything. Too much of that type of training exists, which is probably why youve picked up this book.
My approach here is simple: Short programs. To-the-point demonstrations. Lots of examples. Plenty of exercises. The best way to learn something is by doing it. Each concept presented in this book is coupled with sample code.
The listings are short enough that you can quickly type them in and I recommend that you do so. You can then build and run the code to see how things work. This immediate feedback is not only gratifying, its also a marvelous learning tool. Sample programs are followed by exercises you can try on your own, testing your skills and expanding your knowledge. Suggested answers to the exercises can be found on this books companion website: http://www.c-for-dummies.com/begc4d/exercises
How This Book Works This book teaches the C programming language. It starts out by assuming that you know little to nothing about programming, and it finishes by covering some of the more advanced C operations.
To program in C, you need a computer. This book makes no assumptions about the computer you select: It can be a Windows PC, a Macintosh, or a Linux system. Central to all systems, and to programming in this book, is to set up and use the Code::Blocks integrated development environment, or IDE. Steps to do so are offered in . This book also wastes no time, getting you started immediately in . Nothing is introduced without a full explanation first, although due to the nature of programming, Ive made a few exceptions; theyre carefully noted in the text.