C
Second Edition
Pradip Dey Manas Ghosh
OXFORD
UNIVERSITY PRESS
,© Oxford University Press 2011
ISBN: 978-0-198065-28-9
, C Preface to the
First Edition
Since the evolution of computers, a variety of program- CONTENT AND STRUCTURE
ming languages have come into existence. C stands
Chapter 1 begins by explaining the concept of program-
out among general-purpose programming languages
ming. It discusses the techniques of forming an organized
for its unrivaled mix of portability, flexibility, and ef-
approach to problem solving. It also identifies the differ-
ficiency. It is a versatile language and is commonly used
ent types of programs and the various categories of pro-
for developing application and system programs. C has
gramming languages available. The prescribed tools that
block structures, stand-alone functions, a compact set of
are used in this process are described and explained with
keywords, and very few restrictions. For all these rea-
sufficient examples and diagrams.
sons, learning and using C is a necessity for most pro-
For a beginner, Chapter 2 is undoubtedly the most im-
grammers.
portant chapter that describes the basic elements of C. This
chapter introduces the keywords, the basic data types and
ABOUT THE BOOK their modifiers, operators and their precedence, and ex-
This book is intended for an introductory course on pro- pressions and data type conversion rules. The basic struc-
gramming in C. It assumes no prior programming expe- ture of a C program along with the common commands
rience in C or any other language. Readers will find the used in MS-DOS and UNIX/Linux for compiling and running
explanations lucid and effective. Every feature of C has it has been described at length in this chapter.
been demonstrated with appropriate programs tested and Accepting data from and conveying the results to a user
run on a computer. The output obtained after executing is one of the most important actions desired from a pro-
these programs have also been included. The explana- gram. To satisfy these requirements through the console,
tions have been depicted with suitable diagrams to convey there are some commonly used input and output func-
the concepts more effectively. Readers will be proficient tions in C. These have been explained with illustrations in
at programming after solving the review questions and Chapter 3.
programming exercises given at the end of each chapter. Program flow control and looping constructs in C are ex-
Though every attempt has been made to avoid and check plained in Chapter 4. The general statement format with flow-
errors, we will be grateful to readers if they can bring charts and examples illustrate their significance in programs.
to our notice any errors that may have crept in inadver- Arrays and strings are two important data structures for
tently. handling a cluster of homogeneous data. How such clus-
, vi Preface to the First Edition
ters are declared and handled is explained with ample ex- The appendices contain case studies where the problem
amples in Chapter 5. is first defined and then the algorithm is developed, based
The concept of functions, its form, and its requirement on which the C program is coded. Some sample runs ob-
in a program is discussed in Chapter 6 with well-explained tained during the execution of these programs have also
examples. Recursive functions are also described with been included. It also contains tables for ASCII codes, num-
several examples. Analysis of time and space complexity ber system conversions, escape sequences, operators, data
for an algorithm has also been presented in this chapter. types and data conversion rules, commonly used conver-
One of the most important features of C is pointers. sion characters, and format tags. Among many other useful
Starting with an introduction to pointers, Chapter 7 also topics covered in the appendices, an exhaustive listing of
elaborates on how pointers are used with arrays, strings, C library functions, with programs illustrating how these
and functions. The use of pointers is also described in functions can be put to use, have also been presented.
depth with innumerable examples.
User-defined data types such as structures and unions ACKNOWLEDGEMENTS
are described in Chapter 8. What these data types com-
prise and how these are handled and used are illustrated We thank our students Rakesh Dutta and Niloy Debnath
with examples. for verifying the programs in this book and Sonia Khed-
Creating, amending, appending, and many other opera- wal, Priyanka Nawalkar, Sayantani Saha, and Debolina
tions on files in C is a necessity for storing and retrieving Sharangi for their assistance in the preparation of the
data and programs. This has been covered in Chapter 9 model questions. We are grateful to the staff of Oxford
with sufficient examples. University Press for their continuous cooperation, interest,
Linked list, which is a popular data structure, has been and assistance extended to us during the preparation of the
covered in Chapter 10. Various types of linked lists and the book. We are also thankful to our colleague Mr Manash
different operations that can be carried out on such linked Sinharoy for helping us in preparing the manuscript in
lists have been discussed. In this chapter, readers will also time and Mr Tapas Kumar Tunga and Mr P.N. Pathak for
get to know how pointers are used in constructing this data their assistance in the preparation of the manuscript.
structure. Special thanks are due to Mr Steve Summit for his ar-
Chapter 11 highlights some of the advanced features ticles on C, which have guided us in preparing some of the
of C such as command-line arguments, bit-wise operators, topics in this book. We also wish to thank Mr Vijay Kumar
different memory models, and type qualifiers with several R Zanvar and Mr Jayasima Ananth for the article on point-
illustrations. ers and arrays as also Mr Thomas Jenkins for the article on
Frequently asked questions are always a source of recursion, both of which have served as a guide during the
learning. Some frequently asked questions have been in- development of this manuscript. We express our gratitude
cluded at end of the book, which will help readers to clear to Mr Peter Burden, Mr Mike Banahan, Mr Declan Brady,
any doubts pertaining to programming in C. and Mr Mark Doran for their articles on C.
PRADIP DEY
MANAS GHOSH