Preface – Programming in C, 3/e, 3rd Edition


I am indeed very delighted to present the third edition of Programming in C with elaborated concepts supported with more solved and unsolved problems. I have tried to make the book friendly using simple and lucid language. In this edition, a chapter on Graphics with thought provoking questions and programming examples are added.

This book is proposed for beginners, intermediate level students, and for all those who are pursing education in computers. It would be extremely useful for the students who enroll for diploma, degree in science and engineering, certificate courses in computer languages in training institutes or those who appear for the C aptitude tests/interviews on C Language conducted by various software companies and enhance their C knowledge. It can be used as a reference book for those who want to learn or enrich their knowledge in C.

All the programs given in this book are compiled and run on Turbo C compiler. A few applications are provided in this book which are fully tested and run on Turbo C compiler. The programmer can develop advanced applications based on real-life problems using basics of C language. It contains numerous examples which include solved and unsolved programming exercises that make the book most interesting. Multiple choice questions are also provided at the end of each chapter for testing the skills of a programmer.

An attempt has been made to cover the C syllabi of different branches of various universities. Hence this book can be adopted as a text or a reference book in engineering/degree/diploma and other courses.

In order to bridge the gap between theory and practical, each concept is explained at length in an easy-to-understand manner supported with numerous worked-out examples and programs. The book contains solved illustrative problems and exercises. The programmer can run the solved programs, can see the output and enjoy the concepts of C.


The first chapter describes the fundamental concepts of a computer, components of a computer, an overview of compilers and interpreters, structure of a ‘C’ program, programming rules, how to execute the program, and flowchart for execution of a program. This chapter also presents the techniques of solving a problem using algorithm and flowchart.

Chapter 2 explains the fundamentals of ‘C’. These concepts are essential for writing programs and contain character set supported by C language. Various delimiters used with ‘C’ statements, keywords and identifiers are also provided. Different constants, variables and data types supported by C are also given. This chapter covers the rules for defining variables and methods to initialize them. Dynamic initialization is also presented in this chapter. Type conversion of a variable, type modifiers and wrapping around, constant and volatile variables are also explained.

Chapter 3 covers various C operators and their priorities. This chapter presents arithmetic, relational and logical operators. It also embodies increment, decrement (unary operators) and assignment operators. Other operators such as comma, conditional operator and bitwise operators are presented with programming examples.

Chapter 4 deals with formatted input and output functions such as scanf() and printf() functions. The unformatted functions such as putchar() , getche() and gets() are described in this chapter. Different data types and conversion symbols to be used in the C programs have also been elaborated. The special symbols such as escape sequences together with their applications are also discussed. Few of the commonly used library functions to be used in the programs such as clrscr() and exit() are also described.

Chapter 5 is essential for knowing the decision-making statements in C language. This chapter presents how to transfer the control from one part to the other part of the program. The programmer can make the program powerful by using control statements such as if, if-else, nestedif-else statements and switch case. To change the flow of the program, the programmer can use keywords such as break , continue and goto.

Chapter 6 is devoted to control loop structures in which how statements are executed several times until a condition is satisfied. In this chapter, the reader follows program loop which is also known as iterative structure or repetitive structure. Three types of loop control statements are illustrated with for , while and do-while programming examples. Syntaxes of these control statements are briefed together with programming examples. The other statements such as the break, continue and goto statements are also narrated.

Chapter 7 deals with the array in which the reader can follow how to initialize array in different ways. The theme of this chapter is to understand the array declaration, initialization, accessing array elements and operations on array elements. How to specify the elements of one-, two-and three-or multi-dimensional arrays are explained in detail together with ample examples. The functions such as sscanf() and sprintf() are demonstrated through programming examples. The reader can develop programs after learning this chapter on arrays. This chapter also gives an overview of the string. It covers operations on array such as deletion, insertion and searching an element in the array and how to traverse all the array elements.

Chapter 8 is focused on strings. This chapter teaches you how to learn declaration and initialization of a string. It is also very important to identify the end of the string. This is followed by NULL (‘\0’) character. The various formats for display of the strings are demonstrated through numerous examples.

String handling has strong impact in real-life string problems such as conversion of lower to upper case, reversing, concatenation, comparing, searching and replacing of string elements. It is also discussed how to perform these operations with and without standard library functions. Memory functions such as memcpy(), memove() and memchr() are also illustrated together with programming examples.

Chapter 9 deals with the most important feature of the C language, i.e. pointer, it is important but difficult to understand easily. The reader is made familiar with pointers with numerous examples. The reader is brought to light about declaration and initialization of pointers, and how to access variables using pointers. How pointers are used to allocate memory dynamically at run time is also illustrated using memory allocation functions such as malloc() and calloc() functions. How memory is handled efficiently with pointers is also explained. This chapter consists of arithmetic operations on pointers, pointers and arrays, pointers to pointers and pointers to strings. Memory models are also explained.

Chapter 10 is one more important chapter on functions. How a large size program is divided in smaller ones and how a modular program should be developed is learnt in this chapter. Programmer learns the definition and declaration of function. What are the return statements, types of functions and functions with passing arguments are described in detail. What do you mean by “call by value” and “call by reference”? — Their answers are given with many programming examples. This chapter also incorporates functions and loop statements, function and arrays and association of functions and pointers.

The reader should know that the function always returns an integer value. Besides a function can also return a non-integer data type but function prototype needs to be initialized at the beginning of the program. The recursive nature of function is also explained with suitable example. Direct and indirect recursive functions have been explained with programming examples.

Chapter 11 enlightens on the variables used in C in different situations. It also covers types of variables such as local and global variables. The various storage classes of a variable are also covered in this chapter. Explanations on auto , extern , static and register variables are also presented in this chapter.

Chapter 12 narrates how to make use of preprocessor directives and how various macros are to be used. This chapter enlightens preprocessor directives such as #define , #undef , #include , #line , token pasting and stringizing operations and conditional compilation through C are illustrated. It covers #define directive, undef macro, include directive, predefined macros in ANSI and Turbo C. A reader learns how to display programmer’s own error messages using #error directive and making various warnings on/off displayed by compiler using #pragma directive. You are exposed to predefined macors in ctype.h in this chapter.

Chapter 13 is on structures and unions. A reader can get derived data type using structures and unions. User can decide the heterogeneous data types to be included in the body of a structure. Use of dot operator (.) and pointer (->) are explained for accessing members of structure. Declaration and initialization of structure and union are also explained. The typedef facility can be used for creating user-defined data types and illustrated with many examples. Enumerated data type and union are the important subtitles of this chapter. Enumerated data type provides user-defined data types. Union is a principal method by which the programmer can derive dissimilar data types. The last but not the least the DOS and ROM-BIOS functions and their applications are also explained.

Chapter 14 is on files. This chapter explains the procedure for opening a file, storing information and reading. How to read a file and how to append information are explained in this chapter. Many file handling commands are also discussed. Text and binary files are explained. Command line arguments to accept arguments from command prompt are described. Simulation of various DOS commands with examples is also narrated. A reader is also made familiar with I/O redirections in which MSDOS redirects to send the result to disk instead of seeing information on monitor.

Chapter 15 is on graphics. How to draw various figures/images using C library graphics functions are to be studied from graphics chapter. This chapter enlightens the reader about the initialization of graphics with library graphics functions and number of programming examples. Few programs have been provided on mouse programming.

Chapter 16 enlightens the reader on dynamic memory allocations, memory models and linked lists. Dynamic memory allocation deals with memory functions such as malloc() , calloc() , coreleft() and realloc() and release the allocated memory using free() function. The linked list is described in brief in this chapter. In the linked list, creation of linked list, traversing, searching, inserting and deleting an element are described with figures and programming examples.

Utmost care has been taken to write third edition of the book in order to make it error free. The suggestions and feedback for the improvement of the book are always welcome, the readers can directly mail me at

Ashok N. Kamthane
Amit Ashok Kamthane