COMPUTER SYSTEM IN ‘C’ SYSTEM AND PROGRAMMING IN ‘C’ By Anand K. Tripathi Monika Tripathi...
Transcript of COMPUTER SYSTEM IN ‘C’ SYSTEM AND PROGRAMMING IN ‘C’ By Anand K. Tripathi Monika Tripathi...
COMPUTER SYSTEM
AND PROGRAMMING
IN ‘C’
By
Anand K. Tripathi Monika TripathiProfessor and Director Associate Professor and Principal
Ishwarchand Vidyasagar Institute I.V.S. Polytechnicof Technology Mathura, U.P.Mathura, U.P.
(An Imprint of Laxmi Publications Pvt. Ltd.)An ISO 9001:2008 Company
BENGALURU ● CHENNAI ● COCHIN ● GUWAHATI ● HYDERABADJALANDHAR ● KOLKATA ● LUCKNOW ● MUMBAI ● RANCHI ● NEW DELHI
BOSTON (USA) ● ACCRA (GHANA) ● NAIROBI (KENYA)
COMPUTER SYSTEM AND PROGRAMMING IN ‘C’
© by Laxmi Publications (P) Ltd. All rights reserved including those of translation into other languages. In accordance with the Copyright (Amendment) Act, 2012, 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 or otherwise. Any such act or scanning, uploading, and or electronic sharing of any part of this book without the permission of the publisher constitutes unlawful piracy and theft of the copyright holder’s intellectual property. If you would like to use material from the book (other than for review purposes), prior written permission must be obtained from the publishers.
Printed and bound in India Typeset at Goswami Associates, Delhi
First Edition: 2015ISBN 978-93-83828-47-0
Limits of Liability/Disclaimer of Warranty: The publisher and the author make no representation or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties. The advice, strategies, and activities contained herein may not be suitable for every situation. In performing activities adult supervision must be sought. Likewise, common sense and care are essential to the conduct of any and all activities, whether described in this book or otherwise. Neither the publisher nor the author shall be liable or assumes any responsibility for any injuries or damages arising herefrom. The fact that an organization or Website if 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 must be aware that the Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read.
All trademarks, logos or any other mark such as Vibgyor, USP, Amanda, Golden Bells, Firewall Media, Mercury, Trinity, Laxmi appearing in this work are trademarks and intellectual property owned by or licensed to Laxmi Publications, its subsidiaries or affiliates. Notwithstanding this disclaimer, all other names and marks mentioned in this work are the trade names, trademarks or service marks of their respective owners.
Published in india by
UNIVERSITY SCIENCE PRESS(An Imprint of Laxmi Publications Pvt. Ltd.)
An ISO 9001:2008 Company113, GOLDEN HOUSE, DARYAGANJ, NEW DELHI - 110002, INDIA Telephone : 91-11-4353 2500, 4353 2501 Fax : 91-11-2325 2572, 4353 2528 C—www.laxmipublications.com [email protected] Printed at:
& Bengaluru 080-26 75 69 30
& Chennai 044-24 34 47 26, 24 35 95 07
& Cochin 0484-237 70 04, 405 13 03
& Guwahati 0361-254 36 69, 251 38 81
& Hyderabad 040-27 55 53 83, 27 55 53 93
& Jalandhar 0181-222 12 72
& Kolkata 033-22 27 43 84
& Lucknow 0522-220 99 16
& Mumbai 022-24 91 54 15, 24 92 78 69
& Ranchi 0651-220 44 64
Bran
ches
Dedicated to
Our Respected Parents Smt. Kiran TripathiShri Ram Krishna Tripathi,
Babujee Shri Shabu Nath Srivastava
and
My Lovely Daughters Bhavya and Anushreya
CCCCCONTENTONTENTONTENTONTENTONTENTSSSSS
SECTION-I: FUNDAMENTAL DEVELOPMENT OF COMPUTER SCIENCE
1. ESSENTIALS OF COMPUTERS ................................................................... 3
1.1 Computer Concepts ................................................................................................................ 31.2 Components of a Computer .................................................................................................. 41.3 Block Diagram of Computer and its Working ................................................................... 71.4 Four Basic Operations Performed by a Computer ........................................................... 81.5 Characteristics of Computers ................................................................................................ 81.6 Applications of Computers ................................................................................................... 91.7 Difference between an Analog Computer and a Digital Computer ........................... 111.8 Differentiate among Main Frame Computers, Mini Computers and
Micro Computers ................................................................................................................... 11
2. STRUCTURE OF COMPUTER.................................................................... 14
2.1 Introduction ............................................................................................................................ 142.2 An Understanding of (A) System Software and (B) Application Software ............... 15
3. COMPUTING ENVIRONMENT .................................................................... 18
3.1 Introduction ............................................................................................................................ 18
4. ALGORITHM TECHNIQUES, FLOW CHART AND PSEUDOCODE ......... 20
4.1 Introduction ............................................................................................................................ 204.2 Flowchart ................................................................................................................................ 214.3 Flowchart Symbols, Notes and Flow Lines ...................................................................... 224.4 Difference between a Flowchart and an Algorithm with an Example ....................... 254.5 Pseudocode ............................................................................................................................. 25
Preface ............................................................................................................................................... xiiiAcknowledgement ........................................................................................................................... xv
vii
5. NUMBER SYSTEM ...................................................................................... 30
5.1 Introduction ............................................................................................................................ 305.2 Binary Arithmetic .................................................................................................................. 34
6. PROGRAMMING LANGUAGE.................................................................... 43
6.1 Introduction ............................................................................................................................ 436.2 High Level Programming Language and Systematic Development of Programs ... 466.3 Necessary Steps for Designing and Implementation of Correct, Efficient and
Maintainable Programs ........................................................................................................ 47
7. CONVERTER (COMPILER, LOADER, LINKER)........................................ 50
7.1 Introduction ............................................................................................................................ 507.2 Loader and Linker ................................................................................................................. 51
8. OPERATING SYSTEM ................................................................................ 53
8.1 Introduction ............................................................................................................................ 538.2 Define UNIX ........................................................................................................................... 548.3 Major Features of UNIX Operating System ..................................................................... 558.4 UNIX Shell and its Types ..................................................................................................... 578.5 Basic Commands on UNIX/LINUX .................................................................................. 598.6 LINUX O/S ............................................................................................................................. 628.7 Windows 95/98 ..................................................................................................................... 628.8 Disk Operating System (DOS) ............................................................................................ 638.9 Android Operating System ................................................................................................. 67
9. STRUCTURAL PROGRAMMING................................................................ 68
9.1 Introduction ............................................................................................................................ 689.2 Definition ................................................................................................................................ 689.3 Objective of Structured Programming .............................................................................. 689.4 Multiprocessing ..................................................................................................................... 719.5 Multiprogramming ............................................................................................................... 71
10. ERROR HANDLING AND CODE TESTING AND EDITORS ..................... 73
10.1 Introduction ............................................................................................................................ 7310.2 Code Testing Methodology ................................................................................................. 7510.3 Editor ....................................................................................................................................... 7710.4 Program Development ......................................................................................................... 79
TUTORIALS ................................................................................................. 80
Tutorial-1 ............................................................................................................................................ 80Tutorial-2 ............................................................................................................................................ 83
viii
Tutorial-3 ............................................................................................................................................ 88Tutorial-4 ............................................................................................................................................ 91
SECTION-II: ELEMENTS OF “C”
11. FUNDAMENTALS OF C .............................................................................. 95
11.1 Introduction of ‘C’ ................................................................................................................. 9511.2 Character Set .......................................................................................................................... 9511.3 Keywords ................................................................................................................................ 9611.4 Identifiers ................................................................................................................................ 9711.5 Data Types .............................................................................................................................. 9811.6 Constants ............................................................................................................................... 10011.7 Symbolic Constants ............................................................................................................. 10111.8 Escape Sequences ................................................................................................................ 10111.9 Variables ................................................................................................................................ 102
12. OPERATORS AND EXPRESSIONS ......................................................... 105
12.1 Introduction .......................................................................................................................... 10512.2 Arithmetic Operators and Expression ............................................................................. 10612.3 Relational Operators ........................................................................................................... 10812.4 Logical/Boolean Operators ............................................................................................... 10912.5 Assignment Operators ........................................................................................................ 11012.6 Unary Operators .................................................................................................................. 11112.7 Conditional Operators ........................................................................................................ 11112.8 Bitwise Operators ................................................................................................................ 11212.9 Operator Precedence Groups ............................................................................................ 11412.10 Type Conversions in Expressions .................................................................................... 115
13. DATA INPUT/OUTPUT: DATA TYPES AND OPERATORS .................... 119
13.1 The printf() Function .......................................................................................................... 12013.2 The scanf() Function ........................................................................................................... 12213.3 The getchar() and putchar() Function ............................................................................. 12213.4 gets() and puts() Function .................................................................................................. 12313.5 ‘typedef’ –User Defined Data Type ................................................................................. 12413.6 sizeof() Operator .................................................................................................................. 12513.7 Relational Operators ........................................................................................................... 12613.8 Symbolic Constants ............................................................................................................. 12713.9 Casting Values ..................................................................................................................... 128
14. OUTPUT TECHNIQUES ............................................................................ 134
14.1 Output of Integer Numbers ............................................................................................... 13414.2 Output of Real Numbers .................................................................................................... 136
ix
14.3 Printing of a Single Character ........................................................................................... 13714.4 Printing of String ................................................................................................................. 13714.5 Printing of Mixed-integer and Real Number ................................................................. 14014.6 Printing of Mixed-Character and String ......................................................................... 141
15. CONTROL STRUCTURES ........................................................................ 144
15.1 Branching .............................................................................................................................. 14415.2 Looping ................................................................................................................................. 159
16. ARRAYS AND STRINGS........................................................................... 189
16.1 Introduction.......................................................................................................................... 18916.2 Strings .................................................................................................................................... 211
17. FUNCTIONS ............................................................................................... 223
17.1 Library Functions ................................................................................................................ 22317.2 User Defined Function ....................................................................................................... 22417.3 Library Functions ................................................................................................................ 22417.4 User Defined Functions ...................................................................................................... 22917.5 By Reference ......................................................................................................................... 23517.6 Recursion ............................................................................................................................... 23617.7 Storage Class Variables ...................................................................................................... 239
18. POINTERS ................................................................................................. 249
18.1 Declaring a Pointer Variable ............................................................................................. 25018.2 The Address Operator ........................................................................................................ 25018.3 Pointer Arithmetic ............................................................................................................... 25218.4 Accessing Array Elements Using the Pointer ................................................................ 25318.5 Accessing Character Strings Using Pointer .................................................................... 25418.6 Pointer as Functions ............................................................................................................ 256
19. STRUCTURE AND UNION ........................................................................ 263
19.1 Structures .............................................................................................................................. 26419.2 B–Union ................................................................................................................................. 280
20. DYNAMIC MEMORY ALLOCATION ......................................................... 288
20.1 malloc () ................................................................................................................................. 28820.2 calloc() ................................................................................................................................... 28920.3 realloc() .................................................................................................................................. 28920.4 free() ....................................................................................................................................... 28920.5 sizeof() ................................................................................................................................... 290
x
21. THE STANDARD C PREPROCESSOR .................................................... 294
21.1 Role of Preprocessor Directive .......................................................................................... 29421.2 Types of Preprocessor ........................................................................................................ 294
22. FILE MANAGEMENT................................................................................. 303
22.1 Creating a File ...................................................................................................................... 30322.2 Closing a File ........................................................................................................................ 30422.3 File Input and Output ......................................................................................................... 30422.4 getc() Function ..................................................................................................................... 30422.5 fscanf() Function .................................................................................................................. 30522.6 putc() Function ..................................................................................................................... 30522.7 fprintf() Function ................................................................................................................. 30522.8 feof() Function ...................................................................................................................... 306
23. LINKED LIST AND STACK ....................................................................... 319
23.1 Introduction to Linked List ............................................................................................... 31923.2 Types of Linked list ............................................................................................................. 31923.3 Advantages of Linked List ................................................................................................ 32023.4 Limitation of Linked List ................................................................................................... 321
APPENDICES.................................................................................................... 326
Appendix-A ..................................................................................................................................... 326Appendix-B ...................................................................................................................................... 327Appendix-C ..................................................................................................................................... 328Appendix-D ..................................................................................................................................... 328Appendix-E ...................................................................................................................................... 330Appendix-F ...................................................................................................................................... 331Appendix-G ..................................................................................................................................... 332Appendix-H ..................................................................................................................................... 334
BIBLIOGRAPHY ............................................................................................... 335
INDEX ................................................................................................................ 337
xi
PPPPPREFREFREFREFREFAAAAACECECECECE
This is a book about the Computer System and Programming in ‘C’. If you are seeking a book toincrease your typing speed, expand on your knowledge of word processing, or learn the secrets ofchip fabrication and design, this is not the one for you. However, if you want to become thoroughlyfamiliar with the C programming language and with fundamental knowledge, then you have madea wise choice. The book is in two sections one is for Fundamental Development of ComputerScience and the second is thorough knowledge of ‘C’ language.
It is one thing to read about a language; it is quite another to get involved in it. The best andmost time effective way to absorb a language such as C is to have a terminal or computer availableto you, preferable at your fingertips. You will be exposed to well over one hundred C programs inthis book.
You are encouraged to experiment with the programs illustrated in this text. Familiaritywith the language will bring with it greater understanding; the more you understand about C, themore you will enjoy it.
You might be surprised to find out that C has a rather extensive variety of operators anddata types designed specially to offer you a greater range of options and to permit you to solve amultitude of problems with the minimum of effort. These may range in diversity from book keepingto accounting to problems of mathematics. There is no real limit to the areas in which C can be ofuse. The only limitation is your imagination. At the first opportunity, begin to write your ownprograms. This is an order!
This book is intended for the person with or without programming experience. Noprogramming experience will be assumed, however, nor will we expect the reader to have anymathematical expertise above the standard of high school level. The novice to programming willbe naturally move along at a slower pace than that of the more experienced, simply because thereis often much transfer of knowledge when going from one language to another. The experiencedperson has the distinct advantage of at least knowing what to expect. Such people can probablyskim over much of the more descriptive detail without any loss. Even so, C may have someunexpected surprises for the seasoned programmer too. Whatever your background is, by thetime you have finished reading this book, have answered the myriad of questions, and completedthe suggested exercises, you will have come to know the essentials of the C language. That is theonly purpose of this book.
To help get you involved-probably the most important ingredient to the effective learningof any subject material—each chapter is followed by a list of questions based on the text, for whichanswers are supplied. Section-I contains all questions and answers as whole at the end of sectionand each chapter of Section-II contains related questions.
xiii
Computer System and Programming C
Publisher : Laxmi Publications ISBN : 9789383828470Author : Anand Tripathi,Monika Tripathi
Type the URL : http://www.kopykitab.com/product/11075
Get this eBook
40%OFF