Vous êtes sur la page 1sur 363
Fifth Edition f » "oe Tata McGraw-Hill Published by Tata McGraw Hill Education Private Limited, « 7 West Patel Nagar, New Delhi 110 008 Programming in ANSI C, Se Copyright © 2011, 2007, by Tata McGraw Hill Education Private Limited First reprint 2010 DQLARRYZRABCC No part of this publication may be reproduced or distributed in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise or stored ina database or retrieval system without the prior written permission of the publishers. The program listings (if any) may be entered, stored and executed in a computer system, but they may not bbe reproduced for publication. This edition can be exported from India only by the publishers, ‘Tata MeGraw Hill Education Private Limited. ISBN (13 digits): 978-0-07-068182-8 ISBN (10 digits): 0-07-068182-1 ‘Vice President and Managing Director—McGraw-Hill Education: Asia Pacific Region: Ajay Shukla Head—Higher Education Publishing and Marketing: Vibha Mahajan ‘Manager: Sponsoring—SEM & Tech Ed: Shalini Jha ‘Asst Sponsoring Editor: Surabhi Shukla Development Editor: Surbhi Suman Executive—Editorial Services: Sohini Mukherjee Jr Production Manager: Anjali Razdan Dy Marketing Manager—SEM & Tech Ed: Biju Ganesan General Manager—Production: Rajender P Ghansela Asst General Manager—Production: B L Dogra Information contained in this work has been obtained by Tata MeGraw-Hil, fom sources believed tobe reliable. However, neither Tata McGraw-Hill nor its authors guarantee the accuracy or completeness of any information published herein, and neither Tata McGraw-Hill nor its authors shall be responsible for any errors, omissions, or damages arising out of use of this information. This work is published with the understanding that Tata McGraw-Hill and its authors are supplying information but are not attempting to render engineering or other professional services. If such services are required, the assistance of an appropriate professional should be sought ‘Typeset at Text-o-Graphies, B1/S6 Arawali Apartment, Sector 34, Noida 201301 and printed at Gopsons, A — 2 & 3, Sector — 64, Noida, U.P. - 201 301 Cover Printer: Gopsons McGraw-Hill Copyrighted material Contents Preface to the Fifth Edition xi 1_Overview of C 1 11_ History of C_1 12 Importance of C_3 13 Sample am 1: Printing a Message 3 (14 Sample Program 2: Adding Two Numbers 6 15 Sample Program 3: Interest Calculation 8 16 Sample Program 4: Use of Subroutines 10 ‘LT Sample Program 5: Use of Math Functions 11 18 Basic Structure of C Programs 12 1.9 Programming Style 14 1.10 Executing a‘C’ Program 14 1.11 Unix System _16 1.12 Ms-Dos System _18 Review Questions 19 Programming Exercises 20 2 Constants, Variables, and Data Types 23 2.1 Introduction 23 22 Character Set_23 23 C Tokens 25. 2.4 Keywords and Identifiers 25 (2.5 Constants 26 26 Variables 30 2.7 __DataTypes 31 2.9 Declaratic ‘Storage Class_37 2.10 Assigning Values to Variables 38 2.11 Defining Symbolic Constants 44 2.12 Declaring a Variable as Constant _45 2.13 Declaring a Variable as Volatile 45