1. Programming In C Third Edition Kamthane Ashok N
download
https://ebookbell.com/product/programming-in-c-third-edition-
kamthane-ashok-n-32705058
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Programming In C Volume 2 Composite Data Structures And Modularization
https://ebookbell.com/product/programming-in-c-volume-2-composite-
data-structures-and-modularization-50338946
Programming In C Volume 1 Basic Data Structures And Program Statements
Xingni Zhou
https://ebookbell.com/product/programming-in-c-volume-1-basic-data-
structures-and-program-statements-xingni-zhou-50339330
Programming In C Object Oriented Features Laxmisha Rai Editor China
Science Publishing Media Ltd Editor
https://ebookbell.com/product/programming-in-c-object-oriented-
features-laxmisha-rai-editor-china-science-publishing-media-ltd-
editor-51127748
Programming In C For Engineering And Science 1st Edition Nyhoff
https://ebookbell.com/product/programming-in-c-for-engineering-and-
science-1st-edition-nyhoff-55234332
3. Programming In C Part One Introduction To C Leonard Robbie
https://ebookbell.com/product/programming-in-c-part-one-introduction-
to-c-leonard-robbie-56204050
Programming In C Cover Title Mittal Ajay
https://ebookbell.com/product/programming-in-c-cover-title-mittal-
ajay-21999912
Programming In C 2nd Edition 2nd Edition Safari An Oreilly Media
Company Kamthane
https://ebookbell.com/product/programming-in-c-2nd-edition-2nd-
edition-safari-an-oreilly-media-company-kamthane-22020720
Programming In C Volume 2 Composite Data Structures And Modularization
Zhou
https://ebookbell.com/product/programming-in-c-volume-2-composite-
data-structures-and-modularization-zhou-22736722
Programming In C 3rd Edition Stephen G Kochan
https://ebookbell.com/product/programming-in-c-3rd-edition-stephen-g-
kochan-2580972
6. PROGRAMMING IN C
third Edition
Ashok N. Kamthane
Associate Professor
Shri Guru Gobind Singhji Institute of Engineering
and Technology, Nanded, Maharashtra, India
A01_KAMT3553_02_SE_FM.indd 1 5/17/2015 8:59:35 AM
8. Preface xi
Acknowledgements xiv
About the Author xv
1 Basics and Introduction to C ...............................................................2
1.1 Why to Use Computers? 3
1.2 Basics of a Computer 3
1.3 Latest Computers 5
1.4 Introduction to C 6
1.5 About ANSI C Standard 7
1.6 Machine, Assembly and High-Level Language 7
1.6.1 Assembly Language 8
1.6.2 High-Level Language 8
1.7 Assembler, Compiler and Interpreter 8
1.8 Structure of a C Program 10
1.9 Programming Rules 12
1.10 Executing the C Program 12
1.11 Standard Directories 16
1.12 The First C Program 16
1.13 Advantages of C 17
1.14 Header Files 17
1.15 Algorithm 18
1.15.1 Program Design 20
1.16 Classification of Algorithms 21
1.17 Flowcharts 22
1.18 Pseudocode 26
Summary 28
Exercises 28
2 The C Declarations ............................................................................. 32
2.1 Introduction 33
2.2 The C Character Set 33
2.3 Delimiters 34
Contents
A01_KAMT3553_02_SE_FM.indd 3 5/17/2015 8:59:36 AM
9. iv Contents
2.4 Types of Tokens 35
2.5 The C Keywords 35
2.6 Identifiers 35
2.7 Constants 36
2.7.1 Numerical Constants 37
2.7.2 Character Constant 38
2.8 Variables 39
2.9 Rules for Defining Variables 39
2.10 Data Types 40
2.11 C Data Types 41
2.12 Integer and Float Number Representations 43
2.12.1 Integer Representation 43
2.12.2 Floating-Point Representation 44
2.13 Declaring Variables 44
2.14 Initializing Variables 45
2.15 Dynamic Initialization 46
2.16 Type Modifiers 46
2.17 Type Conversion 47
2.18 Wrapping Around 49
2.19 Constant and Volatile Variables 50
2.19.1 Constant Variable 50
2.19.2 Volatile Variable 50
Summary 51
Exercises 52
3 Operators and Expressions �������������������������������������������������������������� 58
3.1 Introduction 59
3.2 Operator Precedence 59
3.3 Associativity 62
3.4 Comma and Conditional Operator 63
3.5 Arithmetic Operators 64
3.6 Relational Operators 67
3.7 Assignment Operators and Expressions 68
3.8 Logical Operators 71
3.9 Bitwise Operators 74
Summary 80
Exercises 80
A01_KAMT3553_02_SE_FM.indd 4 5/17/2015 8:59:36 AM
10. Contents v
4 Input and Output in C ������������������������������������������������������������������������ 84
4.1 Introduction 85
4.2 Formatted Functions 86
4.3 Flags, Widths and Precision with Format String 88
4.4 Unformatted Functions 99
4.5 Commonly Used Library Functions 104
4.6 Strong Points for Understandability 105
Summary 106
Exercises 106
5 Decision Statements ����������������������������������������������������������������������� 112
5.1 Introduction 113
5.2 The if Statement 114
5.3 The if–else Statement 116
5.4 Nested if–else Statements 120
5.5 The if-else-if Ladder Statement 121
5.6 The break Statement 129
5.7 The continue Statement 130
5.8 The goto Statement 130
5.9 The switch Statement 132
5.10 Nested switch case 144
5.11 The switch case and nested ifs 146
Summary 147
Exercises 148
6 Loop Control ������������������������������������������������������������������������������������ 154
6.1 Introduction 155
6.1.1 What is a Loop? 155
6.2 The for Loop 156
6.3 Nested for Loops 172
6.4 The while Loop 194
6.5 The do-while Loop 207
6.6 The while Loop within the do-while Loop 212
6.7 Bohm and Jacopini’s Theory 213
Summary 213
Exercises 213
A01_KAMT3553_02_SE_FM.indd 5 5/17/2015 8:59:36 AM
11. vi Contents
7 Data Structure: Array ���������������������������������������������������������������������� 220
7.1 Introduction 221
7.2 Array Declaration 221
7.3 Array Initialization 222
7.4 Array Terminology 223
7.5 Characteristics of an Array 224
7.6 One-Dimensional Array 226
7.7 One-Dimensional Array and Operations 238
7.8 Operations with Arrays 240
7.9 Predefined Streams 246
7.10 Two-Dimensional Array and Operations 251
7.10.1 Insert Operation with Two-Dimensional Array 253
7.10.2 Delete Operation with Two-Dimensional Array 255
7.11 Three- or Multi-Dimensional Arrays 269
7.12 The sscanf() and sprintf() Functions 274
7.13 Drawbacks of Linear Arrays 276
Summary 276
Exercises 277
8 Strings and Standard Functions �������������������������������������������������������� 286
8.1 Introduction 287
8.2 Declaration and Initialization of String 287
8.3 Display of Strings with Different Formats 289
8.4 String Standard Functions 291
8.5 String Conversion Functions 315
8.6 Memory Functions 316
8.7 Applications of Strings 318
Summary 328
Exercises 328
9 Pointers ������������������������������������������������������������������������������������������� 336
9.1 Introduction 337
9.2 Features of Pointers 338
9.3 Pointers and Address 338
9.4 Pointer Declaration 339
9.5 The Void Pointers 345
9.6 Wild Pointers 346
9.7 Constant Pointers 347
9.8 Arithmetic Operations with Pointers 348
A01_KAMT3553_02_SE_FM.indd 6 5/17/2015 8:59:36 AM
12. Contents vii
9.9 Pointers and Arrays 352
9.10 Pointers and Two-Dimensional Arrays 357
9.11 Pointers and Multi-Dimensional Arrays 358
9.12 Array of Pointers 360
9.13 Pointers to Pointers 362
9.14 Pointers and Strings 364
Summary 371
Exercises 371
10 Functions ����������������������������������������������������������������������������������������� 378
10.1 Introduction 379
10.2 Basics of a Function 379
10.2.1 Why Use Functions? 379
10.2.2 How a Function Works? 380
10.3 Function Definition 380
10.4 The return Statement 384
10.5 Types of Functions 386
10.6 Call by Value and Reference 393
10.7 Function Returning More Values 395
10.8 Function as an Argument 396
10.9 Function with Operators 399
10.10 Function and Decision Statements 406
10.11 Function and Loop Statements 409
10.12 Functions with Arrays and Pointers 412
10.13 Passing Array to a Function 418
10.14 Nested Functions 420
10.15 Recursion 422
10.16 Types of Recursion 424
10.17 Rules for Recursive Function 425
10.18 Direct Recursion 427
10.19 Indirect Recursion 428
10.20 Recursion Versus Iterations 430
10.21 The Towers of Hanoi 432
10.22 Advantages and Disadvantages of Recursion 435
10.23 Efficiency of Recursion 436
10.24 Library Functions 437
Summary 438
Exercises 438
A01_KAMT3553_02_SE_FM.indd 7 5/17/2015 8:59:36 AM
13. viii Contents
11 Storage Classes ������������������������������������������������������������������������������ 446
11.1 Introduction 447
11.1.1 Lifetime of a Variable 447
11.1.2 Visibility of a Variable 448
11.2 Automatic Variables 448
11.3 External Variables 450
11.4 Static Variables 453
11.5 Static External Variables 454
11.6 Register Variables 455
Summary 456
Exercises 456
12 Preprocessor Directives ����������������������������������������������������������������� 462
12.1 Introduction 463
12.2 The #define Directive 463
12.3 Undefining a Macro 466
12.4 Token Pasting and Stringizing Operators 467
12.5 The #include Directive 468
12.6 Conditional Compilation 469
12.7 The #ifndef Directive 471
12.8 The #error Directive 472
12.9 The #line Directive 473
12.10 The #pragma inline Directive 473
12.11 The #pragma saveregs 473
12.12 The #pragma Directive 473
12.13 The Predefined Macros in ANSI and Turbo-C 475
12.14 Standard I/O Predefined Streams in stdio.h 478
12.15 The Predefined Marcos in ctype.h 478
12.16 Assertions 480
Summary 481
Exercises 481
13 Structure and Union ������������������������������������������������������������������������ 490
13.1 Introduction 491
13.2 Features of Structures 491
13.3 Declaration and Initialization of Structures 492
13.4 Structure within Structure 496
A01_KAMT3553_02_SE_FM.indd 8 5/17/2015 8:59:36 AM
14. Contents ix
13.5 Array of Structures 498
13.6 Pointer to Structure 501
13.7 Structure and Functions 504
13.8 typedef 506
13.9 Bit Fields 510
13.10 Enumerated Data Type 513
13.11 Union 517
13.12 Calling BIOS and DOS Services 518
13.13 Union of Structures 524
Summary 524
Exercises 525
14 Files ������������������������������������������������������������������������������������������������� 532
14.1 Introduction of a File 533
14.2 Definition of File 533
14.3 Streams and File Types 534
14.3.1 File Types 534
14.4 Steps for File Operations 535
14.4.1 Opening of File 536
14.4.2 Reading a File 536
14.4.3 Closing a File 536
14.4.4 Text Modes 537
14.4.5 Binary Modes 543
14.5 File I/O 545
14.6 Structures Read and Write 553
14.7 Other File Function 558
14.8 Searching Errors in Reading/Writing Files 561
14.9 Low-Level Disk I/O 572
14.10 Command Line Arguments 576
14.11 Application of Command Line Arguments 577
14.12 Environment Variables 579
14.13 I/O Redirection 580
Summary 582
Exercises 582
15 Graphics ������������������������������������������������������������������������������������������ 590
15.1 Introduction 591
15.2 Initialization of Graphics 591
15.3 Few Graphics Functions 591
A01_KAMT3553_02_SE_FM.indd 9 5/17/2015 8:59:36 AM
15. x Contents
15.4 Programs Using Library Functions 593
15.4.1 Program on Moving Moon 596
15.5 Working with Text 598
15.5.1 Stylish Lines 599
15.6 Filling Patterns with Different Colours and Styles 600
15.7 Mouse Programming 604
15.8 Drawing Non-common Figures 607
Summary 608
Exercises 608
16 Dynamic Memory Allocation and Linked List �������������������������������� 612
16.1 Dynamic Memory Allocation 613
16.2 Memory Models 613
16.3 Memory Allocation Functions 614
16.4 List 621
16.5 Traversal of a List 621
16.6 Searching and Retrieving an Element 622
16.7 Predecessor and Successor 623
16.8 Insertion 624
16.9 Linked Lists 626
16.10 Linked List with and without Header 627
16.10.1 Linked List with Header 627
Summary 636
Exercises 637
Appendix A ��������������������������������������������������������������������������������� 641
American Standard Code for Information Interchange 641
Appendix B ��������������������������������������������������������������������������������� 649
Priority of Operators and Their Clubbing 649
Appendix C ��������������������������������������������������������������������������������� 651
Header Files and Standard Library Functions 651
Appendix D ��������������������������������������������������������������������������������� 655
ROM-BIOS Services 655
Appendix E ��������������������������������������������������������������������������������� 657
Scan Codes of Keyboard Keys 657
Index ��������������������������������������������������������������������������������������� 660
A01_KAMT3553_02_SE_FM.indd 10 5/17/2015 8:59:36 AM
16. Iam 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.
BOOK ORGANIZATION
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.
Preface
A01_KAMT3553_02_SE_FM.indd 11 5/17/2015 8:59:36 AM
17. xii Preface
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, nested if-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,searchingandreplacingofstringelements.Itisalsodiscussed
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.
A01_KAMT3553_02_SE_FM.indd 12 5/17/2015 8:59:37 AM
18. Preface xiii
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 ankamthane@gmail.com.
Ashok N. Kamthane
A01_KAMT3553_02_SE_FM.indd 13 5/17/2015 8:59:37 AM
19. Iwould like to thank all those who have encouraged me, especially Professor B.M. Naik, former
principal of Shri Guru Gobind Singhji Institute of Engineering and Technology, who has been
always a source of inspiration.
Special thanks are due to members of board of governors of SGGS institute who motivated
me for writing this book, Baba Kalyani, Chairman and Managing Director of Bharat Forge Ltd
Pune, Ram Bhogle, C.Y. Gavhane, Mr Kamlesh Pande, Sanjay Kumar, Dr Nirmal Singh Sehra, and
Director of our Institute Dr L.M. Waghmare.
My sincere thanks to Professor S.D. Mahajan, Director of Technical Education, Maharashtra
State, and ex-Board of Governors of this college, Dr M.B. Kinhalkar, Former Home Minister and
ex-Principal, Dr T.R. Sontakke for inspiring me to write this book.
I am grateful to all my colleagues, friends and students, who extended morale support,
Dr Y.V. Joshi, Dr R.R. Manthalkar, Dr S.S. Gajre, Dr S.V. Bonde, Dr P.G. Jadhav, Professor N.G.
Megde, Professor P.S. Nalawade, Dr A.R. Patil, Dr A.B. Gonde, Dr M.B. Kokre, Dr U.V. Kulkarni,
Dr P. Pramanik, Dr V.M. Nandedkar, Dr A.V. Nandedkar, Dr B.M. Patre, Dr S.T. Hamde, Dr R.C.
Thool, Dr V.R. Thool, Mrs U.R. Kamble, Dr D.D. Doye, Dr V.G. Asutkar, Professor R.K. Chavan,
Professor Ghanwat Vijay, Dr V.K. Joshi, Dr S.G. Kahalekar, Dr A. Chakraborty, Dr P. Kar, Dr P.G.
Solankar, Dr B.M. Dabde, Dr M.L. Waikar, Dr R.S. Holambe, Dr J.V.L. Venkatesh, Mrs S.S.
Kandhare, Professor S.S. Hatkar, Narayan Patil, Dr P.D. Dahe, Dr P.D. Ullagadi, Dr P.B. Londhe,
Dr A.S. Sontakke, Professor A.M. Bainwad, Professor Deepak Bacchewar, Professor R.P. Parvekar,
Professor N.M. Khandare, Dr V.B.Tungikar, Dr R.N. Joshi, Dr L.G. Patil, Professor A.I. Tamboli,
Mr Bhalerao M.V. and Professor S.B. Dethe.
I am also thankful to my friends, Professor S.L. Kotgire, Maruti Damkondawar, G.M. Narlawar,
Anil Joshi, D.V. Deshpande, Professor Balaji Bacchewar, M.M. Jahagirdar, L.M. Buddhewar,
K.M. Buddhewar, S.R. Kokane, Ganpat Shinde, M.G. Yeramwar, S.R. Tumma, S.P. Tokalwad,
P.R. Navghare, Somajawar H.S. and Annes for their morale support.
I am thankful to the wonderful editorial team of Pearson Education for specific invaluable inputs
and bringing this book out in a record time.
I also express my thanks to my son Lecturer Amit, students Jadhav Gopal and Wanjare Sainath
for their critical review and suggesting improvements.
Last but not the least, my thanks are due to my wife Surekha for her patience and support. My son
Amol, daughter Sangita and daughter-in-law Swaroopa were of great help and supported me all the
times.
Ashok N. Kamthane
Acknowledgements
A01_KAMT3553_02_SE_FM.indd 14 5/17/2015 8:59:37 AM
20. Ashok N. Kamthane is presently working as an associate professor in Department of Electronics and
Telecommunication Engineering at Shri Guru Gobind Singhji Institute of Engineering and Technology,
Nanded, Maharashtra. He has over 32 years of teaching experience. He was associated with the
development of hardware and software using 8051 on acoustic transceiver system for submarines.
Professor Kamthane is also the author of bestselling books Object-Oriented Programming with
ANSI and Turbo C++; Introduction to Data Structures in C; and C Programming: Test Your Skills,
published by Pearson Education.
About the Author
A01_KAMT3553_02_SE_FM.indd 15 5/17/2015 8:59:37 AM
22. Basics and
Introduction to C
1
CHAPTER
Chapter Outline
1.1 Why to use Computers?
1.2 Basics of a Computer
1.3 Latest Computers
1.4 Introduction to C
1.5 About ANSI C Standard
1.6 Machine, Assembly and High-Level Language
1.7 Assembler, Compiler and Interpreter
1.8 Structure of a C Program
1.9 Programming Rules
1.10 Executing the C Program
1.11 Standard Directories
1.12 The First C Program
1.13 Advantages of C
1.14 Header Files
1.15 Algorithm
1.16 Classification of Algorithms
1.17 Flowcharts
1.18 Pseudocode
M01_KAMT3553_02_SE_C01.indd 2 5/17/2015 9:04:16 AM
23. Basics and Introduction to C 3
1.1 Why to Use Computers?
Computers play a vital role in the socioeconomic progress of a country. Every nation is paying much
importance to computer literacy. Progress of individuals, surrounding region, nation and of the world
is ensured only with the introduction and use of computers. In every walk of life, computers are being
used increasingly. In every part of the world, computers are employed to increase the overall produc-
tivity. Moreover, the quality of the products due to application of computers is substantially improved.
The impact of computers is very high on mass education, entertainment and productivity in all fields.
With the use of computers the cost of production reduces drastically, a lot of time is saved and the best
quality is ensured.
With the adoption of the policy of liberalization, privatization and globalization by the govern-
ments all over the world, it is necessary to become competitive in the market. Luxurious survival is
not easy as was possible in ancient days. With land, labour, muscle power and capital, economy can
certainly be boosted to a certain degree, but the intellectual power is highly superior to all these assets.
With some know-how (for the common users) and a lot of technical innovations (by the developers),
numerical problems, business transactions and scientific applications, can be computed in almost no
time. A computer does various tasks on the basis of programs. Intellectual computer is certainly a
powerful gadget but human intellectual capability is much higher than that of a computer. Thus, com-
puter does not have its own brain. Brainpower of computer is limited. Thus, human intellectual power
is further reinforced by the use of computers frequently in the day-to-day life. By learning program-
ming languages, developing software packages and using hardware of computers, one can make his/
her life and nation prosperous.
1.2 Basics of a Computer
Data to be processed by a computer appears in different forms, such as numeric, alphabetical char-
acters either in uppercase or in lowercase, special characters and multimedia. Research applications
in universities and colleges frequently use numeric data on large scales, whereas businessmen and
people in the corporate sector use both numeric and
character data. However, in animation multimedia is
used which include text, video and audio.
A computer is a programmable
electronic
machine that accepts instructions and data through
input devices, manipulating data
according to
instructions and finally providing result to the
output device. The result can be stored in memo-
ry or sent to the output device. Figure 1.1 shows
the conventional block diagram of a
conventional
computer.
Figure 1.2 shows a computer system contain-
ing a monitor, a keyboard and a rectangular box
comprising CPU on the motherboard.
In brief, the various blocks of a computer are described as follows.
Input Device: Input device is used to accept the data and instructions in to the computer. Through
the input device, i.e. keyboard, instructions and data are stored in a computer’s memory. Stored
instructions are further read by the computer from its memory and thus a computer manipulates
the data according to the instructions. The various input devices that can be used in a computer are
Central
Processor
Unit
Output
Memory
Input
Figure 1.1 Block diagram of a conventional computer
M01_KAMT3553_02_SE_C01.indd 3 5/17/2015 9:04:17 AM
24. 4 Programming in C
keyboards, mouse, analog-to-digital converters,
light pen, track ball, optical character reader and
scanner. Figure 1.3 shows the input devices of
a computer. Floppy, compact disc, etc. can be
used as input or output device.
Central Processor Unit: CPU is the abbrevia-
tion for central processor unit. It is the heart of the
computer system. It is a hardware device in the
Figure 1.3 Input devices of a computer
CD Keyboard Mouse Floppy Microphone Pen Drive
computer and quite often it called as microprocessor chip. Since it is a tiny chip hence called as mi-
croprocessor chip. This chip is produced from silicon vapor over which millions of transistors are
mounted with modern fabrication techniques.
The brain of the computer is CPU. This chip is responsible to interpret and execute the instruc-
tions. It comprises arithmetic and logical unit, registers and control unit. The arithmetic and logical
unit performs various arithmetic and logical operations on the data based upon the instructions. The
control unit generates the timing and control signals for carrying out operations within the processor.
Registers are used for holding the instructions and storing the results temporarily. Instructions are
stored in the memory and they are fetched one by one and executed by the processor.
Output Device: The output device is used to display the results on the screen or to send the data to
an output device. The processed data is ultimately sent to the output device by the computer. The out-
put device can be a monitor, a printer, an LED, seven-segment display, D to A converter, plotter, and
so on. Figure 1.4 shows different output devices of a computer.
Figure 1.4 Output devices of a computer
Printer CD Floppy Monitor Speaker Hard-Disk
Figure 1.2 computer system
Interface
Memory: Memory is used to store the program. There are two types of semi-conductor memories.
They are as follows:
(i) RAM (Random access memory)
(ii) ROM (Read only memory)
M01_KAMT3553_02_SE_C01.indd 4 5/17/2015 9:04:18 AM
25. Basics and Introduction to C 5
semi-conductor memory is used for storing the instructions and data in the form of ones and zeros.
The memory can be called user’s memory or read–write memory. Processor first reads the instructions
and data from the primary memory (semi-conductor memory). Then, it executes the instructions.
One more memory device used by a computer is called read only memory (ROM). This contains
a fixed software program for providing certain operations. This is non-volatile memory. Its contents
cannot be eliminated when power supply goes off. The basic input–output system (BIOS) is a soft-
ware used to control various peripheral devices such as a keyboard, a monitor, a printer, a mouse,
ports including serial and parallel ports. In fact, this is an operating system. It is possible to access the
users’ written programs, i.e. by loading a file, saving it and doing modifications to it in the later stage.
As soon as a personal computer is switched on, the software gets booted from ROM. Thus, various
functions are assigned to all supporting peripherals of a central processing unit (CPU) and easy inter-
actions are provided to the user by BIOS while booting the system.
For storing volumous data, secondery storage devices can be used. They are optical disk,
magnetic
disc, tapes, etc.
1.3 Latest Computers
The discussion on the various types of computers existing in the market is beyond the scope in this book.
Latest computers available in the market are in various shapes and sizes. These computers are just like
notebooks or even require lesser space than the notebook. They are handy, light weighted and portable.
Because of these reasons many computer users now carry laptops while travelling for their day-to-day
work. In the next couple of years, it is predicted that every school-going child would be using a laptop or
palmtop, and these devices would be sold just like hot cakes in the market with affordable prizes. A lot
of research work is going on in the foreign and Indian Universities, institutes and industries on the reduc-
tion of the size of a computer, building more functions in it with low cost, minimum battery power for
operating it for large duration in the absence ofA.C. mains power supply. In a couple of years, laptops and
palmtops would be flooded in the market. These notebook-shaped laptops are as powerful as desktop com-
puters. In other words, the computing power of a laptop would be advancing to that of desktop computers
and minicomputers. They are used for the purpose of text processing, web surfing, multimedia operation,
image processing and so on. Performances of these computers are constantly improving, and the cost is
drastically reducing.A wireless network can be formed easily with laptops with the Bluetooth technology.
Wifi wireless network is quite popular nowadays, and there we use these computers quite often.
Typical specifications of a laptop computer are as follows,
• Processor: Intel Core i7 ( 8M cache,2.80GHz) OR AMD
• RAM: Minimum 2 GB to Maximum 16 GB
• Hard disk: Minimum 320 GB up to 1 TB or higher
• CD/DVD Drive: Dual Layer DVD+/-RW Drive, SuperDrive, Bluetooth and Camera
• Screen Size: 15.6” up to 23” Flat screen with LCD/LED display
• Ethernet: 10/100/1000 Mbps Ethernet
• Port: USB 3.0
• Graphics Card: From 520 MB or higher
• Rechargeable Battery back up
• Operating system such as windows XP/ windows 7/ Linux
For simpler application, one can go for Celeron-based laptop where heat
generated by the processor is little. Pentium processors are used only for
dedicated applications. Heat generated by this kind of laptop is more and
battery is to be frequently charged (Figure 1.5). Figure 1.5 The laptop
M01_KAMT3553_02_SE_C01.indd 5 5/17/2015 9:04:18 AM
26. 6 Programming in C
The C language is not tied to any particular
operating system. It can be used to develop new
operating systems. Refer to Figure 1.7 in which the
C language is shown associated with the various
operating systems. The C language is closely associat-
ed with the UNIX operating system. The source code
for the UNIX operating system is in C. C runs under
a number of operating systems including MS-DOS.
The C programs are efficient, fast and highly
portable,
i.e. C programs written on one computer can be run on
another with mere or almost no modification.
The C programming language contains modules called functions. The C functions are the basic
building blocks and the most programmers take its benefit. Programmers include these functions in
their program from the C standard library.
C language is a middle-level computer language. It does not mean that C is not powerful and
rugged for writing programs like in Fortran and Pascal. It also does not mean that it is troublesome
like assembly level languages. It combines the features of a high-level language and functionality like
assembly languages. In C, one can develop a program fast and execute fast. It reduces the gap between
high- and low-level languages; that is why it is known as a middle level language. It is well suited for
writing both application and system softwares.
C is a structural language. It has many similarities with the other structural languages such as
Pascal and Fortran. Structured language facilitates the development of a variety of programs in small
modules or blocks. Lengthy programs can be divided into shorter programs. The user requires think-
ing of a problem in terms of functional blocks. With appropriate collection of different modules, the
programmer can make a complete program.
It is easy for writing, testing, debugging and maintenance with structured programming. In case
some changes are to be done in a program, the programmer can refer to the earlier written module
with editor and incorporate the appropriate changes. Hence, structured languages are easier and most
of the developers prefer these languages, than the non-structured languages like BASIC and COBOL.
Programming with non-structured languages is tough in comparison to structured languages.
1.4 Introduction to C
C is one of the most popular general-purpose programming
languages.
C language has been designed and developed by
Dennis Ritchie at
Bell Laboratories, USA, in 1972. Several important
concepts of C
are drawn from ‘Basic combined programming language’ and ‘B’
language. Figure 1.6 shows the development of C
language from the
two languages. Martin Richards developed BCPL in 1967. The impact
of BCPL on C is observed indirectly through the language B, which
was developed by Ken Thompson in 1970. C is also called an offspring of the BCPL. Table 1.1
illustrates the evolution of languages and their inventors of programming language.
Figure 1.7 C and operating systems
UNIX
WINDOWS
MS-DOS
C OTHER
OS......
Table 1.1 Languages and their inventors
Sr. No. Language Inventor Year
1. BCPL Martin Richards 1967
2. B Ken Thompson 1970
3. C Dennis Ritchie 1972
Figure 1.6 Evolution of C
BCPL B
C
M01_KAMT3553_02_SE_C01.indd 6 5/17/2015 9:04:19 AM
27. Basics and Introduction to C 7
C is also called a system-programming language because it is greatly helpful for writing operat-
ing systems, interpreters, editors, compilers, database programs and network drivers.
BCPL and B are data type-less languages. However, C language has a variety of data types. The
standard data types in C are integers, floating point, characters. Also, derived data types can be cre-
ated such as pointers, arrays, structures and unions. Expressions are built from operands and opera-
tors. Any expression or an assignment or a call to function can be a statement. The pointers provide
machine-independent address arithmetic.
C also provides control-flow statements such as decision-making statements (if–else)
and (switch-case) multi-choice statement. C supports for, while and do-while looping
statements.
C does not have any operator to perform operation on composite object. There does not exist any
function or operator that handles entire array or string. For example, to assign elements of one array
to another array simply with single assignment statement is not enough, but an element-to-element
assignment is to be done. However, structure objects can be copied as a unit.
C is not a strongly typed language. But typed statements are checked thoroughly by C compilers.
The compiler will issue errors and warning messages when syntax rules are violated. There is no au-
tomatic conversion of incompatible data types. A programmer has to perform explicit type conversion.
UNIX: The UNIX is an interactive operating system. It is useful in microcomputers, minicomputers
and main frame computers. This operating system is very portable and supports multi-user process-
ing, multi-tasking and networking. Several users can use UNIX at once for performing the same task.
This operating system was developed to connect various machines together. UNIX is primarily used
for workstations and minicomputers.
1.5 About ANSI C Standard
For many years, there was no standard version of C language, and the definition provided in reference
manual was followed. Due to this reason portability feature of C language was not provided from one
computer to another. To overcome this discrepancy, a committee was set up in the summer of 1983 to
create a standard C version which is popularly known asAmerican National Standard Institute (ANSI)
standard.
This committee had defined once and for all a standard C language. The standardization process
took about six years for defining the C language. The ANSI C standard was adopted in 1989, and its
first copy of C language was introduced in the market in 1990.
Thus, ANSI C is internationally recognized as a standard C language. The purpose of this stan-
dard is to enhance the portability and efficient execution of C language programs on different com-
puters. Today, all compilers of C support the ANSI standard. In other words, almost all C compilers
available in the market have been designed to follow ANSI C standard. ANSI C and other C compilers
such as turbo-C version 2 support programs developed in this book.
1.6 Machine, Assembly and High-Level Language
It is a computer’s natural language, which can be directly understood by the system. This language
is machine dependent, i.e. it is not portable. A program written in 1’s and 0’s is called a machine
language. A binary code is used in a machine language for a specific operation. A set of instructions
in binary pattern is associated with each computer. It is difficult to communicate with a computer in
terms of 1s and 0s. Hence, writing a program with a machine language is very difficult. Moreover,
speed of writing, testing and debugging is very slow in machine language. Chances of making careless
errors are bound to be there in this language. The machine language is defined by the hardware design
of that hardware platform. Machine languages are tedious and time consuming.
M01_KAMT3553_02_SE_C01.indd 7 5/17/2015 9:04:19 AM
28. 8 Programming in C
1.6.1 | Assembly Language
Instead of using a string of binary bits in a machine language, programmers started using English-
like words as commands that can be easily interpreted by programmers. In other words, the computer
manufacturers started providing English-like words abbreviated as mnemonics that are similar to
binary instructions in machine languages. The program is in alphanumeric symbols instead of 1s and
0s. The designer chooses easy symbols that are to be remembered by the programmer, so that the
programmer can easily develop the program in assembly language. The alphanumeric symbols are
called mnemonics in the assembly language. The ADD, SUB, MUL, DIV, RLC and RAL are some
symbols called mnemonics.
The programs written in other than the machine language need to be converted to the machine
language. Translators are needed for conversion from one language to another. Assemblers are used
to convert assembly language program to machine language. Every processor has its own assembly
language. For example, 8085 CPU has its own assembly language. CPUs such as 8086, 80186, 80286
have their own assembly languages.
Following disadvantages are observed with the assembly languages:
(i) It is time consuming for an assembler to write and then test the program.
(ii) Assembly language programs are not portable.
(iii)
It is necessary to remember the registers of CPU and mnemonic instructions by the
programmer.
(iv)
Several mnemonic instructions are needed to write in assembly language than a single line
in high-level language. Thus, assembly language programs are longer than the high language
programs.
1.6.2 | High-Level Language
Procedure-oriented languages are high-level languages. These languages are employed for easy and
speedy development of a program. The disadvantages observed with assembly languages are over-
come by high-level languages. The programmer does not need to remember the architecture and reg-
isters of a CPU for developing a program. The compilers are used to translate high-level language
program to machine language. Examples of HLL are COBOL, FORTRAN, BASIC, C and C++. The
following advantages are observed with HLL languages:
(i) Fast program development.
(ii) Testing and debugging a program is easier than in the assembly language.
(iii) Portability of a program from one machine to other.
1.7 Assembler, Compiler and Interpreter
A program is a set of instructions for performing a particular task. These instructions are just like
English words. The computer interprets the instructions as 1’s and 0’s. A program can be written in
assembly language as well as in high-level language. This written program is called the source pro-
gram. The source program is to be converted to the machine language, which is called an object pro-
gram. A translator is required for such a translation.
Program translator translates source code of programming language into machine language-
instruction code. Generally, computer programs are written in languages like COBOL, C, BASIC
and ASSEMBLY LANGUAGE, which should be translated into machine language before execution.
M01_KAMT3553_02_SE_C01.indd 8 5/17/2015 9:04:19 AM
29. Basics and Introduction to C 9
Programming language translators are classified as
follows. A list of translators is given in Figure 1.8.
Translators are as follows:
(i) Assembler
(ii) Compiler
(iii) Interpreter
Assembler: An assembler translates the symbolic
codes of programs of an assembly language into
machine language instructions (Figure 1.9). The symbolic language is translated to the machine code
in the ratio of one is to one symbolic instructions to one machine code instructions. Such types of
Figure 1.9 Assembler
Mnemonic
language
Assembler
Machine
codes
Figure 1.10 Compiler/interpreter
Mnemonic
language
Compilers and
interpreters
Machine
codes
languages are called low-level languages. The assembler programs translate the low-level language
to the machine code. The translation job is performed either manually or with a program called as-
sembler. In hand assembly, the programmer uses the set of instructions supplied by the manufacturer.
In this case, the hexadecimal code for the mnemonic instruction is searched from the code sheet. This
procedure is tedious and time-consuming. Alternate solution to this is the use of assemblers. The pro-
gram called assembler provides the codes of the mnemonics. This process is fast and facilitates the
user in developing the program speedily.
Compiler: Compilers are the translators, which
translate all the instructions of the program into
machine codes, which can be used again and
again (see Figure 1.10). The program, which is
to be translated, is called the source program
and after translation the object code is gener-
ated. The source program is input to the compiler. The object code is output for the secondary storage
device. The entire program will be read by the compiler first and generates the object code. However,
in interpreter each line is executed and object code is provided. M-BASIC is an example of an inter-
preter. High-level languages such as C, C++ and Java compilers are employed. The compiler displays
the list of errors and warnings for the statements violating the syntax rules of the language. Compilers
also have the ability of linking subroutines of the program.
Interpreter: Interpreters also come in the group of translators. It helps the user to execute the source
program with a few differences as compared to compilers. The source program is just like English
statements in both interpreters and compilers. The interpreter generates object codes for the source
program. Interpreter reads the program line by line, whereas in compiler the entire program is read by
the compiler, which then generates the object codes. Interpreter directly executes the program from
its source code. Due to this, every time the source code should be inputted to the interpreter. In other
words, each line is converted into the object codes. It takes very less time for execution because no
intermediate object code is generated.
Figure 1.8 Translators
Translator
Assembler Interpreter
Compiler
M01_KAMT3553_02_SE_C01.indd 9 5/17/2015 9:04:20 AM
30. 10 Programming in C
Linking: C language provides a very large library, which contains numerous functions. In some
applications of C the library may be a very large file. Linker is a program that combines source
code and codes from the library. Linking is the process of bringing together source program and
library code.
The library functions are relocatable. The addresses of various machine codes are defined abso-
lutely and only the offset information is kept. When the source program links with the standard library
functions, offset of the memory addresses is used to create the actual address.
1.8 Structure of a C Program
Every C program contains a number of building blocks known as functions. Each function of
it performs a specific task independently. A C program comprises different sections shown in
Figure 1.11.
(i) Include Header File Section: C program
depends upon some header files for function
definition that are used in the program. Each
header file has extension ‘.h’. The
header
files are included at the beginning of the
program in the C language. These files should
be included using # include directive as given
below.
Example:
# include stdio.h or
#
include “stdio.h”
In this example, stdio.h file is
included,
i.e. all the definitions and prototypes of function
defined in this file are available in the current
program. This file is also compiled with the orig-
inal program. The programmer can include the
appropriate header files while executing solved
or unsolved programming examples given in this
book.
(ii) Global Declaration: This section declares some variables that are used in more than one func-
tion. These variables are known as global variables. This section must be declared outside of
all the functions.
(iii) Function main(): Every program written in C must contain main() and its execution starts
at the beginning of this function. In ASCII C standard, first line of C program from where
program execution begins is written as follows.
int main(void)
This is the function definition for main(). Parenthesis followed to main is to tell the user
again that main() is a function. The int main(void) is a function that takes no argu-
ments and returns a value of type int. Here in this line, int and void are keywords and they
have special meanings assigned by the compiler. In case int is not mentioned in the above
statement, by default the function returns an integer.
Global Declaration
/* comments */
/*Function name */
main ()
{
/* comments */
Declaration part
Executable part
Function call
}
User-defined functions
Include header file
Figure 1.11 Structure of a C program
M01_KAMT3553_02_SE_C01.indd 10 5/18/2015 12:14:34 PM
31. Basics and Introduction to C 11
Alternately, one can also write the first line of C program from where program execution be-
gins is as follows.
void main(void)
Here, this function takes no arguments and returns nothing. Alternately, one can also write the
same function as follows.
void main(): This functions returns nothing and takes no arguments.
In all chapters, in maximum programming examples the main function is written as void
main(). This procedure is followed in this book only to avoid writing return statement at
the end of each program. This step helps to minimize source code lines. At few places in this
book, main function is initialized with int main(void). In such a case, return state-
ment is used at the end of program (before closing brace). The programmer can either write
the function main with int main(void) or void main(). Only in the formal case,
return statement should be used before the end of function for terminating the execution of
the main function.
The program contains statements that are enclosed within the braces. The opening brace ({)
and closing brace (}) are used in C. Between these two braces, the program should declare
declaration and executable part. The opening curly brace specifies the start of the definition of
the main function. The closing curly brace specifies the end of the code for the main function.
(iv) Declaration Part: The declaration part declares the entire local variables that are used in
executable part. Local variable scope is limited to that function where the local variables are
declared. The initializations of variables can also be done in this section. The initialization
means providing initial value to the variables.
(v) Executable Part: This part contains the statements following the declaration of the variables.
This part contains a set of statements or a single statement.
(vi) Function Call: From the main() a user defined function can be invoked by the user as per
need/application.
(vii) User-defined Function: The functions defined by the user are called user-defined functions.
These functions are defined outside the main() function.
(viii) Body of the Function: The statements enclosed within the body of the function (between
opening and closing brace) are called body of the function.
(ix) Comments: Comments are not necessary in a program. However, to understand the flow of
programs a programmer can insert comments in the program. Comments are to be inserted by
the programmer. It is useful for documentation. The clarity of the program can be followed if
it is properly documented.
Comments are statements that give us information about the program which are to be placed
between the delimiters /* and */. The programmers in the programs for enhancing the
lucidity frequently use comments. The compiler does not execute comments. Thus, we can say
that comments are not a part of executable programs.
A user can frequently use any number of comments that can be placed anywhere in a
program. Please note that comment statements can be nested. The user should select the
OPTION MENU of the editor and select the COMPILER-SOURCE - NESTED COMMENTS
ON/OFF. The comments can be inserted with single statement or in nested statements.
M01_KAMT3553_02_SE_C01.indd 11 5/17/2015 9:04:20 AM
32. 12 Programming in C
Example:
/* This is single comment */
/* This is an example of /* nested comments */*/
/* This is an example of
of comments in
multiple lines */ /* It can be nested */
1.9 Programming Rules
A programmer while writing a program should follow the following rules:
(i) Every program should have main() function.
(ii) C statements should be terminated by a semi-colon. At some places, a comma operator is per-
mitted. If only a semi-colon is placed it is treated as a statement. For example:
while(condition)
;
The above statement generates infinite loop. Without semi-colon the loop will not execute.
(iii) An unessential semi-colon if placed by the programmer is treated as an empty statement.
(iv) All statements should be written in lowercase letters. Generally, uppercase letters are used
only for symbolic constants.
(v) Blank spaces may be inserted between the words. This leads to improvement in the readability
of the statements. However, this is not applicable while declaring a variable, keyword, constant
and function.
(vi) It is not necessary to fix the position of statement in the program; i.e. a programmer can write
the statement anywhere between the two braces following the declaration part. The user can
also write one or more statements in one line separating them with a semi-colon (;). Hence, it
is often called a free-form language. The following statements are valid:
a=b+c;
d=b*c;
or
a=b+c; d=b*c;
(vii) The opening and closing braces should be balanced, i.e. if opening braces are four; closing
braces should also be four.
1.10 Executing the C Program
A C program must go through various phases such as creating a program with editor, execution of
preprocessor program, compilation, linking, loading and executing the program. The following steps
are essential in C when a program is to be executed in MS-DOS mode:
(i) Creation of a Program: The program should be written in C editor. The file name does not
necessarily include extension ‘.C’. The default extension is ‘.C’. The user can also specify
his/her own extension. The C program includes preprocessor directives.
(ii) Execution of a Preprocessor Program: After writing a program with C editor the program-
mer has to compile the program with the command (Alt-C). The preprocessor program executes
M01_KAMT3553_02_SE_C01.indd 12 5/17/2015 9:04:20 AM
33. Basics and Introduction to C 13
first automatically before the compilation of the program. A programmer can include other files
in the current file. Inclusion of other files is done initially in the preprocessor section.
(iii) Compilation and Linking of a Program: The source program contains statements that are to be
translated into object codes. These object codes are suitable for execution by the computer. If a
program contains errors the programmer should correct them. If there is no error in the program,
compilation proceeds and translated program is stored in another file with the same file name with
extension ‘.obj’. This object file is stored on the secondary storage device such as a disc.
Linking is also an essential process. It puts together all other program files and functions that
are required by the program. For example, if the programmer is using pow() function, then
the object code of this function should be brought from math.h library of the system and
linked to the main() program. After linking, the program is stored on the disc.
(iv) Executing the Program: After the compilation the executable object code will be loaded in the
computer’s main memory and the program is executed. The loader performs this function.All the
above steps/phases of C program can be performed using menu options of the editor.
As shown in Figure 1.12, pre-processor directories/program is executed before compilation
of the main program. The compiler checks the program and if any syntax error is found, the same
Figure 1.12 Flow chart of a program in C
Source program editor
Pre-processor
Execute object code
Logic error
Output
Compile time error
Run time error
No
Yes Yes
Input error Is logic and data
error?
Input again
Yes
No
Linking process
System library
Is syntax
error?
Compile source program
M01_KAMT3553_02_SE_C01.indd 13 5/17/2015 9:04:21 AM
34. 14 Programming in C
is displayed. The user is again forced to go to edit window. After removing an error, the compiler
compiles the program. Here, at this stage object code is generated. During the program execution, if
user makes mistakes in inputting data, the result would not be appropriate. Therefore, the user again
has to enter the data. The output is generated when a program is error free.
Editing, compiling and executing a program file with an editor (Figure 1.13):
Figure 1.13 Window to Turbo C editor
The programmer can use the Turbo C editor/compiler. The Turbo C editor is a software, in which the
programmer can write the program in C source code. The window to Turbo C editor appears when we
invoke shortcut to TC icon, which can be placed on desktop. This window is used for editing, compil-
ing and running the program.
Its menu bar comprises eight menus: File, Edit, Run, Compile, Project, Options, Debug and
Break/watch.
File: This menu is used for creating a new program file, loading an existing C file, writing the file
with appropriate path, invoking DOS (OS Shell), changing directory and quitting the program.
Edit: The Edit menu provides editing options.
Run: The Run menu provides options such as Run, Program reset, Go to cursor, Trace into, Step
over and User screen.
On pressing Alt+F keys, one can go to the File menu and select either New for creating a new
file or in case file is already existing then use Load option and load the file by giving the appropriate
path. Extension of the file with .c is automatically provided by the editor. The programmer can put
extension .c or by default .c is provided by the editor. The programmer can now write a program with
C syntax.
It is better to create and save programs in a separate folder/subdirectory in the home directory of
the disk. The folder/subdirectory is the working directory. This is due to the association of the program
file with several files created during compiling and running. Files created are your own files (source
code file and data files) and besides, some other files created are after compilation and running the
program.
For example if C:Turboc2 is home directory, a subdirectory can be created with the
Command
prompt. Assume that the created subdirectory is Vishal, then working directory path would be
C:Turboc2Vishal. So, create and save all programs in the working directory Vishal (Figure 1.14).
M01_KAMT3553_02_SE_C01.indd 14 5/17/2015 9:04:21 AM
35. Basics and Introduction to C 15
Figure 1.14 Opening a new file
After editing the program file, the same should be saved either with F2 key or Alt+F Save from File
menu and compiled from compile menu. Now programmer can use the keysAlt+C in the editor as shown
below (Figure 1.15).
Figure 1.15 Compilation of program
On compilation, the same program is to be run with Alt+R keys. The screen appears as shown below. Of
course, this step is adapted when there are no errors after compilation. After running the program,
answer
appears on the other screen. The programmer can try a simple program as cited below in the window.
Executable file is created after running the program file. The .exe file created can be observed (Figure 1.16).
Figure 1.16 Running a program
It is expected to edit, compile and run a program given in the above snapshot by the user in the C editor.
M01_KAMT3553_02_SE_C01.indd 15 5/17/2015 9:04:22 AM
36. 16 Programming in C
1.11 Standard Directories
The turbo-C has three standard directories; they are include, sys and lib. The Sys is the
sub-directory of include. The include directory contains all the header files and lib con-
tains all the library files. Before executing the program the path setting should be done. In turbo-
c edit, select Option menu Directories option. Here, set the path of include, library and
turbo-c-directories.
1.12 The first C program
1.1 Write a program to display message “Hello! C Programmers”.
void main()
{
printf(“Hello! C Programmers”);
}
OUTPUT:
Hello! C Programmers
Explanation:
This program displays the message ‘Hello! C Programmers’ using the printf()
statement. Follow the following steps to execute the program through Turbo-c editor.
After typing a program by pressing F2, a program can be saved. If you are saving for the first
time, a name will be asked. Type the file and the extension (.c) will automatically be added.
By pressing ALT+C you can reach the compile option. Also by pressing F9, you can compile
the program. To execute the program you can press CTRL + F9. To see the output of the
program, press ALT+F5. User can make exe file by pressing F9 key twice.
1.2 Write a program to know about the use of comments (how to use comments?).
void main()
{
clrscr(); /* clears the screen */
printf(“This program explains comments”);
/* How to use comment? */
}
OUTPUT:
This program explains comments
Explanation:
In the above program, we can observe how comments are inserted in a program. The
comments are not an executable part. It is only useful for the programmer to understand
the flow of a program. This program prints the message as shown in the output.
The function clrscr() clears the screen, defined in header file conio.h.
Although the file is not included, some compilers allow execution and some will flag
an error message.
M01_KAMT3553_02_SE_C01.indd 16 5/17/2015 9:04:22 AM
37. Basics and Introduction to C 17
main()
{
return 0;
}
1.3 Write a program to return the value from main()
.
Explanation:
The above program produces no output. The main() should return a value of either 0 or 1.
Some operating systems check the return value of main(). If main() returns 0, i.e. pro-
gram executed successfully; else for other value OS assumes the opposite. If user fails to put
the return statement, the compiler would not complain.
1.13 Advantages of C
(i) It contains a powerful data definition. The data type supported are characters, alphanumeric,
integers, long integer, floats and double. It also supports string manipulation in the form of
character array.
(ii) C supports a powerful set of operators.
(iii) It also supports powerful graphics programming and directly operates with hardware. Execu-
tion of program is faster.
(iv) An assembly code is also inserted into C programs.
(v) C programs are highly portable on any type of OS platforms.
(vi) System programs such as compilers, operating systems can be developed in C. For example,
the popular operating system UNIX is developed in C.
(vii) The C language has 32 keywords and about 145 library functions and near about 30 header
files.
(viii) C works closely with machines and matches assembly language in many ways.
1.14 Header Files
stdio.h: Standard input and output files. All formatted and unformatted functions include file
operation functions defined in this file. The most useful formatted printf() and scanf() are
defined in this file. This file must be included at the top of the program. Most useful functions from
this header files are printf(), scanf(), getchar(), gets(), putc() and putchar().
conio.h: Console input and output. This file contains input and output functions along with a few
graphic-supporting functions. The getch(), getche() and clrscr() functions are defined in
this file.
math.h: This file contains all mathematical and other useful functions. The commonly useful func-
tions from this files are floor(), abs(), ceil(), pow(), sin(), cos() and tan(). The list
of commonly used header files are given in Table 1.2
M01_KAMT3553_02_SE_C01.indd 17 5/17/2015 9:04:22 AM
38. 18 Programming in C
There are different ways of representing the logical steps for finding a solution of a given problem.
They are as follows:
(i) Algorithm
(ii) Flowchart
(iii) Pseudo-code
In the algorithm, a description of the steps for solving a given problem is provided. Here, stress is given on the
text. Flowchart represents the solution of a given problem graphically. Pictorial representation of the logical
steps is a flowchart.Another way to express the solution of a given problem is by means of a pseudo-code.
1.15 Algorithm
Algorithm is a very popular technique used to obtain a solution for a given problem. The algorithm
is defined as ‘the finite set of steps, which provide a chain of actions for solving a definite nature of
problem’. Each step in the algorithm should be well defined. This step will enable the reader to trans-
late each step into a program. Gradual procedure for solving a problem is illustrated in this section.
An algorithm is a well-organized, pre-arranged and defined textual computational module that
receives some value or set of values as input and provides a single value or a set of values as output.
These well-defined computational steps are arranged in a sequence, which processes the given input
into an output. Writing precise description of the algorithm using an easy language is most essential
for understanding the algorithm. An algorithm is said to be accurate and truthful only when it provides
the exact required output. Lengthy procedure is sub-divided into small parts and thus steps are made
easy to solve a given problem. Every step is known as an instruction.
In our daily life, we come across numerous algorithms for solving problems. We perform several
routine tasks, for example riding a bike, lifting a phone, making a telephone call, switching on a televi-
sion set and so on.
For example, to establish a telephonic communication between two subscribers, following steps
are to be followed:
(i) Dial a phone number
(ii) Phone rings at the called party
(iii) Caller waits for the response
(iv) Called party picks up the phone
Table 1.2 Commonly useful header files
Sr. No. Header File Functions Function Examples
1. stdio.h Input, output and file operation functions printf(), scanf()
2. conio.h Console input and output functions clrscr(), getche()
3. alloc.h Memory allocation-related functions malloc(), realloc()
4. graphics.h All graphic-related functions circle(), bar3d()
5. math.h Mathematical functions abs(), sqrt()
6. string.h String manipulation functions strcpy(), strcat()
7. bios.h BIOS accessing functions biosdisk()
8. assert.h Contains macros and definitions void assert(int)
9. ctype.h Contains prototype of functions which test
characters
isalpha(char)
10. time.h Contains date- and time-related functions asctime()
M01_KAMT3553_02_SE_C01.indd 18 5/17/2015 9:04:22 AM
39. Basics and Introduction to C 19
(v) Conversation begins between them
(vi) After the conversation, both disconnect the call
Another real life example is to access Internet through Internet service provider with dial up facility.
To log on to the Internet, the following steps are to be followed:
(i) Choose the Internet service provider for accessing the Internet.
(ii) Obtain from service provider a dial up number.
(iii) Acquire IP address of the service provider.
(iv) Acquire login ID and password.
(v) Run the Internet browsing software.
When one writes an algorithm, it is essential to know how to analyse the algorithm. Analysing al-
gorithm refers to calculating or guessing resources needed for an algorithm. Resources mean com-
puter memory, processing time, logic gates. In all the above factors, time is the most important factor
because the program developed should be faster in processing. The analysis can also be made by
reading the algorithm for logical accuracy, tracing the algorithm, implementing it, and checking with
some data and with mathematical techniques to confirm its accuracy.
Algorithms can also be expressed in a simple method. It will help the user to put into operation
easily. However, this approach has a few drawbacks. It requires more space and time. It is very essen-
tial to consider the factors such as time and space of an algorithm. With minimum resources of system
such as CPU’s time and memory, an efficient algorithm must be developed.
Practically, it is not possible to do a simple analysis of an algorithm to conclude the execution time of an
algorithm. The execution time is dependent upon the machine and the way of implementation. The timing
analysis depends upon the input required. To accurately carry out the time analysis, it is also very essential
to know the exact directives executed by the hardware and the execution time passed for each statement.
1.4 Write a program to swap two numbers using a third variable.
Algorithm for swapping two numbers:
STEP 1: Start.
STEP 2: Declare variables a, b, c.
STEP 3: Read values of a b.
STEP 4: Copy value of a to c; b to a; c to b.
STEP 5: Print swapped values of a b.
STEP 6: Exit.
Program:
void main()
{
int a,b,c;
clrscr();
printf(“nEnter two numbers for A B:”);
scanf(“%d %d”,a,b);
c=a;
a=b;
b=c;
printf(“nAfter swaping the values
are:A=%d B=%d.”,a,b);
getch();
}
START
c = a;
a = b;
b = c;
END
Enter the values of
a b
Declare variables a, b, c.
Print a, b
Flowchart for swapping
two numbers:
M01_KAMT3553_02_SE_C01.indd 19 5/17/2015 9:04:23 AM
40. 20 Programming in C
START
END
Print values
of a b
Declare variables
assign values to a b.
a = a + b;
b = a − b;
a = a − b;
Flowchart:
Hint: Copy value of a in third variable c, value of b in a, and value of c in b.
Explanation:
In the above cited program, first three variables a, b, c are declared. The program invokes
two values of a b from user. The user assigns values to the variables a b.
Now copy the value of a in third variable c, value of b in a, and value of c in b.
Here, when we assign the value of a to c (c = a), the value of a is copied in variable c. When we
assign (a = b), the value of b is copied in variable a and the previous value is replaced. Now,
b holds the value of variable c in statement (b = c).
The printf( ) statement prints the values of a b.
1.5 Write a program to swap two numbers without using a third variable.
Algorithm:
STEP 1: Start.
STEP 2: Declare two variables a b.
STEP 3: Addition of a b and place result in a.
STEP 4: Subtraction of a b and place result in b.
STEP 5: Subtraction of a b and place result in a.
STEP 6: Print values of a b.
STEP 7: End.
Program:
void main()
{
int a=4,b=6;
clrscr();
a=a+b;
b=a-b;
a=a-b;
printf(“nthe value of a=%d b=%d”,a,b);
getch();
}
OUTPUT:
The value of a=6 b=4
Explanation:
In the above cited program, first two variables a b are declared and initialized.
Values of a b are added in the statement a = a + b. In the next statement, b is subtracted from
a and result is stored in b. Finally, the value of a is obtained by subtracting b from a.
The printf( ) statement prints the values of a b.
1.15.1 | Program Design
When you have thoroughly studied the program and examined the requirement of the program, the
next step is to design the program. To make the programs simple, divide the program into smaller
modules. This makes thinking process easy and you can separately apply logic on each portion. After
dividing the program, according to priority and importance write the code.
M01_KAMT3553_02_SE_C01.indd 20 5/17/2015 9:04:23 AM
41. Basics and Introduction to C 21
Coding Programs: Coding a program is the second step. Once you have understood the program,
now you can implement through the code. If a program is short, start coding from the beginning to
top in a sequence. Identify the different variables and selection or control structures required. Also
write comments so that you can follow them in future. While coding, appropriate messages for user’s
direction should be prompted.
Testing Programs: After completing the coding of a program, the next step is to test the program.
Confirm that the required source files and data files are at the specified location in the system.
1.16 Classification of Algorithms
The classification of algorithm is based on repetitive steps and on control transfer from one statement
to another. Figure 1.17 shows the classification of Algorithms.
Figure 1.17 Classifications of algorithms
Direct Indirect Deterministic Non-deterministic Random
Based on repetitive
steps
Based on control
transfer
Algorithms
On the basis of repetitive steps, an algorithm can further be classified into two types.
(i) Direct Algorithm: In this type of algorithm, the number of iterations is known in advance.
For example, for displaying numerical numbers from 1 to 10, the loop variable should be ini-
tialized from 1 to 10. The statement would be as follows:
for (j=1;j=10;j++)
In the above statement, it is predicted that the loop will iterate 10 times.
(ii) Indirect Algorithm: In this type of algorithm, repetitively steps are executed. Exactly how
many repetitions are to be made is unknown.
For example, the repetitive steps are as follows:
(i)
To find the first five Armstrong numbers from 1 to n, where n is the fifth Armstrong
number.
(ii) To find the first three palindrome numbers.
M01_KAMT3553_02_SE_C01.indd 21 5/17/2015 9:04:24 AM
42. 22 Programming in C
Based on the control transfer, the algorithms are categorized in the following three types.
(i) Deterministic: Deterministic algorithm is based on either to follow a ‘yes’ path or ‘no’ path
based on the condition. In this type of algorithm when control comes across a decision logic,
two paths ‘yes and ‘no’ are shown. Program control follows one of the routes depending upon
the condition.
Example:
Testing whether a number is even or odd. Testing whether a number is positive or negative.
(ii) Non-deterministic: In this type of algorithm to reach to the solution, we have one of the mul-
tiple paths.
Example:
To find a day of a week.
(iii) Random algorithm: After executing a few steps, the control of the program transfers to
another step randomly, which is known as a random algorithm.
Example:
A random search
Another kind of an algorithm is the infinite algorithm.
Infinite algorithms: This algorithm is based on better estimates of the results. The number
of steps required would not be known in advance. The process will be continued until the best
results emerged. For final convergence more iterations would be required.
Example:
To find shortest paths from a given source to all destinations in the network.
1.17 FLOWCHARTS
A flowchart is a visual representation of the sequence of steps for solving a problem. It enlightens
what comes first, second, third, and so on. A completed flowchart enables you to organize your prob-
lem into a plan of actions. Even for designing a product a designer many times has to draw a flowchart.
It is a working map of the final product. This is an easy way to solve the complex designing problems.
The reader follows the process quickly from the flowchart instead of going through the text.
A flowchart is an alternative technique for solving a problem. Instead of descriptive steps, we use
pictorial representation for every step. It shows a sequence of operations.A flowchart is a set of symbols,
which indicates various operations in the program. For every process, there is a corresponding symbol
in the flowchart. Once an algorithm is written, its pictorial representation can be done using flowchart
symbols. In other words, a pictorial representation of a textual algorithm is done using a flowchart.
We give below some commonly used symbols in flowcharts.
Start and end: The start and end symbols indicate both the beginning and the end of the flowchart.
This symbol looks like a flat oval or is egg shaped. Figure 1.18 shows the symbol of Start/stop. Only
one flow line is combined with this kind of symbol. We write START, STOP or END in the symbols
of this kind. Usually this symbol is used twice in a flowchart, that is, at the beginning and at the end.
Start
Stop
Figure 1.18 Start/stop symbol
M01_KAMT3553_02_SE_C01.indd 22 5/17/2015 9:04:24 AM
43. Basics and Introduction to C 23
Decision or test symbol: The decision symbol is diamond shaped. This symbol is used to take one
of the decisions. Depending on the condition the decision block selects one of the alternatives. While
solving a problem, one can take a single, two or multiple alternatives depending upon the situation.All
these alternatives are illustrated in this section. A decision symbol with a single alternative is shown in
Figure 1.18. In case the condition is satisfied /TRUE a set of statement(s) will be executed otherwise
for false the control transfers to exit.
Single alternative decision: Here more than one flow line can be used depending upon the condi-
tion. It is usually in the form of a ‘yes’ or ‘no’ question, with branching flow line depending upon the
answer. With a single alternative, the flow diagram will be as per Figure 1.19.
Entry
Condition?
Execution of statement(s)
Exit
True False
Figure 1.19 Single alternative decision
Two alternative decisions: In Figure 1.20 two alternative paths have been shown. On satisfying the
condition statement(s) pertaining to 1 action will be executed, otherwise the other statement(s) for
action 2 will be executed.
Entry
Condition?
Execution of action 2
Execution of action 1
Exit
True False
Figure 1.20 Two alternative decisions
Multiple alternative decisions: In Figure 1.21 multiple decision blocks are shown. Every decision
block has two branches. In case the condition is satisfied, execution of statements of appropriate
blocks take place, otherwise next condition will be verified. If condition 1 is satisfied then block 1
statements are executed. In the same way, other decision blocks are executed.
M01_KAMT3553_02_SE_C01.indd 23 5/17/2015 9:04:24 AM
44. 24 Programming in C
Entry
Condition 1
Condition 2
Condition 3
Execution of block 1
Execution of block 2
Execution of block 3
True
True
True
False
False
False
Exit
Figure 1.21 Multiple alternative decisions
Connector symbol: A connector symbol has to be shown in the form of a circle. It is used to establish
the connection, whenever it is impossible to directly join two parts in a flowchart. Quite often, two
parts of the flowcharts may be on two separate pages. In such a case, connector can be used for joining
the two parts. Only one flow line is shown with the symbol. Only connector names are written inside
the symbol, that is, alphabets or numbers. Figure 1.22 shows the connector symbol.
Connector for connecting
to the next block
Connector that comes from the
previous block
Figure 1.22 Connector symbol
Process symbol: The symbol of process block should be shown by a rectangle. It is usually used for
data handling, and values are assigned to the variables in this symbol. Figure 1.23 shows the process
symbol. The operations mentioned within the rectangular block will be executed when this kind of
block is entered in the flowchart. Sometimes an arrow can be used to assign the value of a variable to
another. The value indicated at its head is replaced by the tail values. There are two flow lines con-
nected with the process symbol. One line is incoming and the other line goes out.
Z = X + Y
P = X * Y
Figure 1.23 Process symbol
M01_KAMT3553_02_SE_C01.indd 24 5/17/2015 9:04:25 AM
45. Basics and Introduction to C 25
Loop symbol: This symbol looks like a hexagon. This symbol is used for implementation of for
loops only. Four flow lines are associated with this symbol. Two lines are used to indicate the
sequence of the program and remaining two are used to show the looping area, that is, from the
beginning to the end.
For the sake of understanding, Figure 1.24. illustrates the working of for loop. The variable J is
initialized to 0 and it is to be incremented by a step of 2 until it reaches the final value 10. For every
increased value of J, body of the loop is executed. This process will be continued until the value of J
reaches 10. Here the next block is shown for the repetitive operation.
Entry
Exit
To continue the
for loop
Body of the
for loop
For J = 0 to 10 by
step 2
Figure 1.24 For loop
Input/output symbol: Input/output symbol looks like a parallelogram, as shown in Figure 1.25. The
input/output symbol is used to input and output the data. When the data is provided to the program for
processing, then this symbol is used. There are two flow lines connected with the input/output symbol.
One line comes to this symbol and the other line goes from this symbol.
As per Figure 1.25 compiler reads the values of X, Y and in the second figure the result is dis-
played on the monitor or the printer.
Read X, Y Print X, Y
Figure 1.25 Input/output symbol
Figure 1.26 Delay symbol
Delay symbol: Symbol of delay is just like ‘AND’ gate. It is used for adding delay to the process. It is
associated with two lines. One is incoming and the other is outgoing, as shown in Figure 1.26.
M01_KAMT3553_02_SE_C01.indd 25 5/17/2015 9:04:26 AM
46. 26 Programming in C
Figure 1.27 Manual input symbol
Manual input symbol: This is used for assigning the variable values through the keyboard, whereas
in data symbol the values are assigned directly without manual intervention. Figure 1.27 represents
the symbol of manual input.
In addition, the following symbols (Figure 1.28) can be used in the flowchart and they are parts
of flowcharts.
Alternate process Predefined process Internal storage
Manual operation
Punched tape Summing junction Or Collate
Sort Extract Merge Stored data
Sequential access
storage
Display Direct access
storage
Off-page connector Card Flow lines
Figure 1.28 Some other symbols used in the flowchart
1.18 PSEUDOCODE
In pseudocodes english-like words are used to represent the various logical steps. It is a prefix repre-
sentation. Here solution of each step is described logically. The pseudocode is just the raw idea about
the problem. By using this tip, one can try to solve the problem. The meaning of pseudocode is ‘false
code.’ The syntax rule of any programming language cannot be applied to pseudocode.
Example (a): Assume a and b are two numbers and find the larger out of them. In such a case, com-
parison is made between them.
M01_KAMT3553_02_SE_C01.indd 26 5/17/2015 9:04:27 AM
47. Basics and Introduction to C 27
This can be represented as follows.
Algorithm Pseudocode
Input a and b. get numbers a b
Is ab. Compare a b
If yes a is larger than b. if a is large max=a
If no b is larger than a. if b is large max=b
Print the larger number. Larger number is max
Few skilled programmers prefer to write pseudocode for drawing the flowchart. This is because using
pseudocode is analogous to writing the final code in the programming language. Few programmers
prefer to write the steps in algorithm. Few programmers favour flowchart to represent the logical flow
because with visualization things are clear for writing program statements. For beginners a flowchart
is a straightforward tool for writing a program.
Example (b): The example (b) illustrates how the pseudo code is used to draw the flowchart for squar-
ing a number.
(i) Accept number
(ii) Calculate square of the number
(iii) Display number
All the steps of the program are written down in steps. Some programs follow pseudocode to draw
flowcharts. Using pseudocode, final program can be written. Majority of programs have common
tasks such as input, processing and output. These are fundamental tasks of any program.
Using pseudocode a flowchart can be drawn as per the following steps.
For the statement, that is, ‘Accept number’ the flowchart symbol is as per Figure 1.29.
Accept
number
Figure 1.29 Input symbol
The statements including arithmetic operations are examples of processing statements. The repre-
sentation of second statement ‘Calculate square of the number’ can be represented as in Figure 1.30.
Calculate square
of the number
Figure 1.30 Processing symbol
The output statement, that is, ‘Display number’ can be represented as per Figure 1.31.
Display
number
Figure 1.31 Output symbol
In addition,the flowchart has two more symbols to indicate the beginning and the end of the program
as per Figure 1.32 The standard terminator symbol is racetrack.
M01_KAMT3553_02_SE_C01.indd 27 5/17/2015 9:04:28 AM
48. 28 Programming in C
1. C Language is developed by Ken Thompson.
2. C Language was developed in the year 1972.
3. C Language is closely associated with Linux.
4. C Programs are not portable.
5. The ANSI C standard was developed in 1989.
6. C Programs are translated into object code by a
compiler.
7. An interpreter reads one line at a time.
8. Every C Program should have the main()
function.
9. In C, all the statements should be written in small
letters only.
10. After compilation, the object file of a source pro-
gram is created.
11. It is not possible to crate .exe file in C.
12. Compiler executes a program even if the program
contains warning messages.
Begin
Begin
1. Accept number
2. Calculate square of
the number
3. Display number
Accept
number
Calculate square
of the number
Display
number
End End
Figure 1.32 Pseudocode and flowchart of a program
exerCises
I True or false:
sUmmary
This chapter presents the evolution and basics of C. C is a structural language. It has many similari-
ties like other structural languages such as Pascal and Fortran. C is also called a system-programming
language. The ANSI C standard was adopted in December 1989 and the first copy of C language was
introduced in the market in 1990.
The reader is exposed to an assembler that translates the symbolic code of programs of an
assembly language into machine language instructions. Similarly, compilers are the translators, which
translate all the instructions of the program into machine codes and can be used again and again. An
interpreter comes in the group of translators. It helps the user to execute the source program with few
differences as compared to compilers.
In this chapter, an overview of algorithms was given. An algorithm is defined as ‘the finite set of
the steps, which provide a chain of actions for solving a definite nature of problem’. Algorithms are of
two types, direct algorithm and indirect algorithm.
M01_KAMT3553_02_SE_C01.indd 28 5/17/2015 9:04:28 AM
49. Basics and Introduction to C 29
II Select the appropriate option from the multiple choices given below:
1. The C language has been developed by
(a) Patrick Naughton
(b) Dennis Ritche
(c) Ken Thompson
(d) Martin Richards
2. The C programming is a
(a) high-level language
(b) low-level language
(c) middle-level language
(d) assembly language
3. The C programs are converted into machine lan-
guage using
(a) an assembler
(b) a compiler
(c) an interpreter
(d) an operating system
4. The C language was developed in the year
(a) 1972
(b) 1980
(c) 1975
(d) 1971
5. The C language has been developed at
(a) AT T Bell Labs, USA
(b) IBM, USA
(c) Borland International, USA
(d) Sun Microsystems
6. The C language is an offspring of the
(a) ‘BPCL’ language
(b) ‘ALGOL’ language
(c) ‘Basic’ language
(d) None of the above
7. The C program should be written only in
(a) lower case
(b) upper case
(c) title case
(d) sentence case
8. The role of a compiler is to translate source
program statements to
(a) object codes
(b) octal codes
(c) decimal codes
(d) None of the above
9. The extension for C program files by default is
(a) ‘.c’
(b) ‘.d’
(c) ‘.obj’
(d) ‘.exe’
10. The C can be used with
(a) only UNIX operating system
(b) only LINUX operating system
(c) only MS-DOS operating system
(d) All the above
11. The C language is closely associated with
(a) MS-DOS
(b) LINUX
(c) UNIX
(d) MS-windows
12. The C programs are highly portable means
(a)
same programs execute on different computers
(b)
program executes only on the same computer
(c) program needs a lot of modification to run
(d) None of the above
13. In Turbo-C editor Alt+C is used to execute the
program.
14. A comment can be split in more than one line.
15. The source code for the UNIX operating system
is in C.
16. The assembly language program is in alphanu-
meric symbols.
17. Linking software is used to bring together the
source program and library code.
18. Assembler translates low-level language to ma-
chine code.
19. The compiler reads firstly entire program and
generates the object code.
20. C does not have automatic conversion of compat-
ible variable.
21. Every processor has its own assembly language.
22. Assembly language program is portable.
M01_KAMT3553_02_SE_C01.indd 29 5/17/2015 9:04:28 AM
50. 30 Programming in C
13. Each instruction in C program is terminated by
(a) dot (.)
(b) comma (,)
(c) semi-colon (;)
(d) curly brace ({})
14. Which one of the following statements is incorrect?
(a) a compiler compiles the source program
(b)
an assembler takes as assembly program as
input
(c)
interpreter executes the complete source
code just like compiler
(d) None of the above
15. ANSI committee was set up in
(a) 1983
(b) 1985
(c) 1990
(d) 1976
16. The program which translates high-level program
into its equivalent machine language program is
called
(a) a translator
(b) a language processor
(c) a converter
(d) None of the above
17. C is an offspring of the
(a) basic combined programming language
(b) basic computer programming language
(c) basic programming language
(d) None of the above
18. An interpreter reads the source code of a
program
(a) one line at a time
(b) two lines at a time
(c) complete program in one stroke
(d) None of the above
19. A compiler reads the source code of a program
(a) complete program in one stroke
(b) one line at a time
(c) two lines at a time
(d) None of the above
20. C keywords are reserved words by
(a) a compiler
(b) an interpreter
(c) a header file
(d) Both (a) and (b)
21. The declaration of C variable can be done
(a) anywhere in the program
(b) in declaration part
(c) in executable part
(d) at the end of program
22. Variables must begin with character without
spaces but it permits
(a) an underscore symbol ( _ )
(b) an asterisk symbol ( )
(c) an ampersand symbol ( )
(d) None of the above
23. In C, the statements following main() are
enclosed within
(a) {}
(b) ()
(c)
(d) None of the above
24. CPU generates
(a) timing signals
(b) control signals
(c) analog signals
(d) both a b
25. The structural languages are
(a) C
(b) Pascal
(c) Fortan
(d) All the above
26. Data type-less languages are
(a) C
(b) BCPL
(c) B
(d) Both c b
27. Input device/s of a computer
(a) Printer
(b) Speaker
(c) Monitor
(d) None of the above
28. Output device/s of the computer
(a) Monitor
(b) Speaker
(c) Printer
(d) All the above
29. CPU comprises of the
(a) Arithmetic and Logical unit
(b) Registers
(c) Control Signals
(d) All the above
M01_KAMT3553_02_SE_C01.indd 30 5/17/2015 9:04:28 AM
51. Basics and Introduction to C 31
III Answer the following questions:
ansWers
1. Why to use a computer? Brief its benefits.
2. Illustrate the functions of various parts of a
computer.
3. Why is the C language called a middle-level
language?
4. What are the functions of an interpreter and a
compiler?
5. What is the difference between an interpreter and
a compiler?
6. What is meant by compilation? Explain in detail.
7. Write the rules for writing a C program.
8. Elaborate different sections of a C program.
9. Explain the functions of a linker.
10. What is the role of curly braces ({}) in a
C program?
11. What is ANSI C standard?
12. What are the user-defined functions?
13. Explain the assembly-language and machine-lan-
guage concepts.
14. Write details on header files stdio.h and
conio.h.
15. Which are the standard directories? Where are .h
files kept?
16. Write any three advantages of a C language.
17. What is an algorithm? Explain in short.
18. Mention and explain two types of algorithms.
19. Show the flowchart for finding cube of a number.
20. Write the pseudo code for finding largest out of
three numbers.
I True or false:
Q. Ans. Q. Ans. Q. Ans. Q. Ans. Q. Ans.
1. F 2. T 3. F 4. F 5. T
6. T 7. T 8. T 9. T 10. T
11. F 12. T 13. F 14. T 15. T
16. T 17. T 18. T 19. T 20. T
21. T 22. F
II Select the appropriate option from the multiple choices given below:
Q. Ans. Q. Ans. Q. Ans. Q. Ans. Q. Ans.
1. b 2. c 3. b 4. a 5. a
6. a 7. a 8. a 9. a 10. d
11. c 12. a 13. c 14. c 15. a
16. a 17. a 18. a 19. a 20. a
21. b 22. a 23. a 24. d 25. d
26. d 27. d 28. d 29. d 30. d
30. Advantages of high level language are
(a) fast Program Development
(b) testing and Debugging of program is easier
(c) portable
(d) All the above
M01_KAMT3553_02_SE_C01.indd 31 5/17/2015 9:04:29 AM
52. 2 The C
Declarations
CHAPTER
Chapter Outline
2.1 Introduction
2.2 The C Character Set
2.3 Delimiters
2.4 Types of Tokens
2.5 The C Keywords
2.6 Identifiers
2.7 Constants
2.8 Variables
2.9 Rules for Defining Variables
2.10 Data Types
2.11 C Data Types
2.12 Integer and Float Number Representations
2.13 Declaring Variables
2.14 Initializing Variables
2.15 Dynamic Initialization
2.16 Type Modifiers
2.17 Type Conversion
2.18 Wrapping Around
2.19 Constant and Volatile Variables
M02_KAMT3553_02_SE_C02.indd 32 5/17/2015 9:05:07 AM
53. The C Declarations 33
2.1 Introduction
The programming languages are designed to support certain kind of data, such as numbers, characters,
strings, etc., to get useful output known as result/information. Data consists of digits, alphabets and symbols.
A program should support these data types for getting the required output known as information.
A program is a set of statements, which performs a specific task, executed by users in a sequential
form. These statements/instructions are formed using certain words and symbols according to the
rules known as syntax rules or grammar of the language. Every program must accurately follow the
syntax rules supported by the language.
In this chapter, C character set, the type of variables, types of tokens, delimiters, data types,
variable initialization and dynamic initialization are described.
2.2 The C Character Set
A character is a part of a word, sentence or paragraph. By using different characters, words, expres-
sions and statements can be created on the basis of the requirement. This creation depends upon the
computer on which a program runs.
A character is represented by any al-
phabets in lowercase or uppercase, digits
or special characters.
Figure 2.1 presents valid C
character
set which are as follows: (i) Letters
(ii)
Digits (iii) White Spaces Escape
Sequences and (iv) Special Characters.
As C character set consists of escape
sequences so each escape sequence begins with back slash () and it represents a single character. Any
character can be represented as character constant using escape sequence.
The complete character set is listed in Tables 2.1 and 2.2.
Table 2.1 Character set
Letters Digits White Spaces and Escape Sequences
Uppercase A to Z All decimal digits 0 to 9 Back space b
Lowercase a to z Horizontal tab t
Vertical tab v
New line n
Form feed f
Backslash
Alert bell a
Carriage return r
Question mark ?
Single quote ’
Double quote ”
Octal number o or oo or ooo
Hexadecimal number xhh
ALPHABETS
DIGITS
WHITE SPACES AND
ESCAPE SEQUENCES
SPECIAL CHARACTERS
C character set
Figure 2.1 C character set
M02_KAMT3553_02_SE_C02.indd 33 5/17/2015 9:05:07 AM
54. 34 Programming in C
The special characters listed in Table 2.2 are represented in the computer by numeric values. The C
characters are assigned unique codes. There are many character codes used in the computer system.
The widely and standard codes used in computer are ASCII and EBCDIC (Extended Binary Coded
Decimal Interchange Code).
Table 2.2 List of special characters
, Comma Ampersand
. Period or dot ^ Caret
; Semi-colon * Asterisk
: Colon _ Minus sign
‘ Apostrophe + Plus sign
“ Quotation mark Less than
! Exclamation mark Greater than
| Vertical bar () Parenthesis (left/right)
/ Slash [] Brackets (left/right)
Back slash {} Curly braces (left/right)
˜ Tilde % Percent sign
_ Underscore # Number sign or hash
$ Dollar = Equal to
? Question mark @ At the rate
Table 2.3 Delimiters
Delimiters Symbols Uses
Colon : Useful for label
Semi-colon ; Terminates statements
Parenthesis () Used in expression and function
Square brackets [] Used for array declaration
Curly braces {} Scope of statement
Hash # Preprocessor directive
Comma , Variable separator
Angle brackets Header file
ASCII Code: ASCII stands for American Standard Code for Information Interchange, is the
code of two types. One uses 7 bits and other uses 8 bits. The 7-bit code represents 128 different
characters and the 8-bit code represents 256 characters. For example, the character A is represented
in 7-bit code as 10000012
(decimal 65). Refer to Appendix A for the list of characters and their
equivalent number.
2.3 Delimiters
The language pattern of C uses special kind of symbols, which are called delimiters. They are depicted
in Table 2.3.
M02_KAMT3553_02_SE_C02.indd 34 5/17/2015 9:05:07 AM
56. .....
But there the night is close, and there
Darkness is cold and strange and bare;
And the secret deeps are whisperless;
And rhythm is all deliciousness;
And joy is in the throbbing tide,
Whose intricate fingers beat and glide
In felt bewildering harmonies
Of trembling touch; and music is
The exquisite knocking of the blood.
Space is no more, under the mud;
His bliss is older than the sun.
Silent and straight the waters run.
The lights, the cries, the willows dim,
And the dark tide are one with him.
We see, all through this poem (and the more convincingly as the
whole of it is studied) the fundamental brain-stuff: the patient
constructive force of intellect keeping pace with fancy every step of
the way. So, too, with Dining-Room Tea. Imagination here is busy
with an idea that is wild, elusive, intangible: on the bare edge, in
fact, of sanity and consciousness. It is that momentary revelation,
which comes once in a lifetime perhaps, of the reality within
appearance. It comes suddenly, unheralded and unaccountable: it is
gone again with the swiftness and terror of a lightning-flash. But in
the fraction of a second that it endures, æons seem to pass and
things unutterable to be revealed. Only a poet of undoubted genius
could re-create such a moment, for on any lower plane either
imagination would flag or intellect would be baffled, with results
merely chaotic. And only to one whose quick and warm humanity
held life's common things so dear could the vision shine out of such
a homely scene. But therein Rupert Brooke shows so clearly as the
poet of his day: that through the familiar joys of comradeship and
laughter: through the simple concrete things of a material world—
the pouring tea and cup and cloth, Reality gleams eternal.
57. When you were there, and you, and you,
Happiness crowned the night; I too,
Laughing and looking, one of all,
I watched the quivering lamplight fall
.....
Flung all the dancing moments by
With jest and glitter....
Till suddenly, and otherwhence,
I looked upon your innocence.
For lifted clear and still and strange
From the dark woven flow of change
Under a vast and starless sky
I saw the immortal moment lie.
One instant I, an instant, knew
As God knows all. And it and you
I, above Time, oh, blind! could see
In witless immortality.
But the precise characteristic of this poetry is not one or other of
these individual gifts. It is an intimate and subtle blending of them
all, shot through and through with a gallant spirit which resolutely
and gaily faces truth. From this brave and clear mentality comes a
sense of fact which finds its artistic response in realism. Sometimes
it will be found operating externally, on technique; but more often,
with truer art, it will wed truth of idea and form, in grace as well as
candour. From its detachment and quick perception of incongruity
comes a rare humour which can laugh, thoughtfully or derisively,
even at itself. It will stand aside, watching its own exuberance with
an ironic smile, as in The One Before the Last. It will turn a
penetrating glance on passion till the gaudy thing wilts and dies. It
will pause at the height of life's keenest rapture to call to death an
undaunted greeting:
58. Breathless, we flung us on the windy hill,
Laughed in the sun, and kissed the lovely grass.
You said, Through glory and ecstasy we pass;
Wind, sun, and earth remain, the birds sing still,
When we are old, are old.... And when we die
All's over that is ours; and life burns on
Through other lovers, other lips, said I,
—Heart of my heart, our heaven is now, is won!
We are Earth's best, that learnt her lesson here.
Life is our cry. We have kept the faith! we said;
We shall go down with unreluctant tread
Rose-crowned into the darkness! ... Proud we were,
And laughed, that had such brave true things to say.
—And then you suddenly cried, and turned away.
Perception so keen and fearless, piercing readily through the half-
truths of life and art, has its own temptation to mere cleverness.
Thence come the conceits of the sonnet called He Wonders
Whether to Praise or Blame Her, a bit of the deftest juggling with
ideas and words. Thence, too, the allegorical brilliance of the
Funeral of Youth; and the merry mockery of the piece called
Heaven. This is an excellent example of the poet's wit, as distinct
from his richer, more pervasive, humour. It is very finely pointed and
closely aimed in its satire of the Victorian religious attitude. And if
we put aside an austerity which sees a shade of ungraciousness in it,
we shall find it a richly entertaining bit of philosophy:
Fish say, they have their Stream and Pond;
But is there anything Beyond?
This life cannot be All, they swear,
For how unpleasant, if it were!
One may not doubt that, somehow, Good
Shall come of Water and of Mud;
And, sure, the reverent eye must see
A Purpose in Liquidity.
59. We darkly know, by Faith we cry,
The future is not Wholly Dry.
Mud unto Mud!—Death eddies near—
Not here the appointed End, not here!
But somewhere, beyond Space and Time,
Is wetter water, slimier slime!
.....
And in that Heaven of all their wish,
There shall be no more land, say fish.
But, on the whole, one loves this work best when its genius is not
shorn by the sterile spirit of derision. Its charm is greatest when the
creative energy of it is outpoured through what is called personality.
Never was a poet more lavish in the giving of himself, yielding up a
rich and complex individuality with engaging candour. And poems
will be found in which all its qualities are blended in a soft and
intricate harmony. Passion is subdued to tenderness: imagination
stoops to fantasy: thought, in so far as it is not content merely to
shape the form of the work, is bent upon ideas that are wistful, or
sad or ironic. Humour, standing aloof and quietly chuckling, will play
mischievous pranks with people and things. A satirical imp will dart
into a line and out again before you realize that he is there; and all
the time a clear-eyed, observing spirit will be watching and taking
note with careful accuracy.
Of such is The Old Vicarage, Grantchester, in which the poet is
longing for his home in Cambridgeshire as he sits outside a café in
Berlin. The poem is therefore a cry of homesickness, a modern Oh,
to be in England! But there is much more in it than that; it is not
merely a wail of emotion. The lyrical reverie which recalls all the
sweet natural beauty that he is aching to return to is closely woven
with other strands. So that one may catch half a dozen incidental
impressions which pique the mind with contrasting effects and yet
contribute to the prevailing sense of intolerable desire for home.
Thus, when the poet has swung off into a sunny dream of the old
60. house and garden, the watching sense of fact suddenly jogs him into
consciousness that he is not there at all, but in a very different
place. And that wakens the satiric spirit, so that an amusing
interlude follows, summing up by implication much of the contrast
between the English and German minds:
... there the dews
Are soft beneath a morn of gold.
Here tulips bloom as they are told;
Unkempt about those hedges blows
An English unofficial rose;
And there the unregulated sun
Slopes down to rest when day is done,
And wakes a vague unpunctual star,
A slippered Hesper; and there are
Meads towards Haslingfield and Coton
Where das Betreten's not verboten.
.....
εἴθε γενοίμην ... would I were
In Grantchester, in Grantchester!—
He slips back again into the softer mood of memory, not of the
immediate home scenes only, but of their associations, historical and
academic. Always, however, that keen helmsman steers to the
windward of sentimentality: better risk rough weather, it seems to
say, than shipwreck on some lotus-island. And every time the boat
would appear to be making fairly for an exquisite idyllic haven, she is
headed into the breeze again. But though she gets a buffeting, and
even threatens to capsize at one moment in boisterous jest, she
comes serenely into port at last.
Say, do the elm-clumps greatly stand
Still guardians of that holy land?
The chestnuts shade, in reverend dream,
61. The yet unacademic stream?
Is dawn a secret shy and cold
Anadyomene, silver-gold?
And sunset still a golden sea
From Haslingfield to Madingley?
And after, ere the night is born,
Do hares come out about the corn?
Oh, is the water sweet and cool,
Gentle and brown, above the pool?
And laughs the immortal river still
Under the mill, under the mill?
Say, is there Beauty yet to find?
And Certainty? and Quiet kind?
Deep meadows yet, for to forget
The lies, and truths, and pain?... oh! yet
Stands the Church clock at ten to three?
And is there honey still for tea?
62. William H. Davies
I should think that the work of Mr Davies is the nearest approach
that the poetic genius could make to absolute simplicity. It is a
wonderful thing, too, in its independence, its almost complete
isolation from literary tradition and influence. People talk of Herrick
in connexion with this poet; and if they mean no more than to
wonder at a resemblance which is a marvellous accident, one would
run to join them in their happy amazement. But there is no evidence
of direct influence, any more than by another token we could
associate his realism with that of Crabbe. No, this is verse which has
growed, autochthonic if poetry ever were, unliterary, and
spontaneous in the many senses of that word.
From that one fact alone, these seven small volumes of verse are a
singular phenomenon. But they teem with interest of other kinds
too. First and foremost there is, of course, the preciousness of many
of the pieces they contain, as pure poetry, undimmed by any other
consideration whatsoever. That applies to a fair proportion of this
work; and it is a delightsomeness which, from its very independence
of time and circumstance, one looks quite soberly to last the
centuries through; and if it lapse at all from favour, to be
rediscovered two or three hundred years hence as we have
rediscovered the poets of the seventeenth century.
It has, however, inherent interest apart from this æsthetic joy,
something which catches and holds the mind, startling it with an
apparent paradox. For this poetry, with its solitariness and absence
of any affiliation ancient or modern, with its bird-note bubbling into
song at some sweet impulse and seemingly careless of everything
but the impelling rapture, is at the same time one of the grimmest
pages out of contemporary life. In saying that, one pauses for a
63. moment sternly to interrogate one's own impression. How much of
this apparent paradox is due to knowledge derived from the author's
astounding autobiography? Turn painfully back for a moment to the
thoughts and feelings aroused by that book: recall the rage against
the stupidity of life which brings genius to birth so carelessly,
endowing it with appetites too strong for the will to tame and senses
too acute for the mind to leash until the soul had been buffeted and
the body maimed. And admit at once that such a tale, all the more
for its quiet veracity, could not fail to influence one's attitude to this
poetry. No doubt it is that which gives assurance, certainty, the proof
of actual data, to the human record adumbrated in the poems. But
the record is no less present in the poems. It often exists, implicit or
explicit, in that part of the verse which sings because it must and for
sheer love of itself. And in that other part of the work where the lyric
note is not so clear: in the narrative poems and queer character-
studies and little dramatic pieces, the record lives vivid and almost
complete. Perhaps it is the nature of the record itself which denies
full inspiration to those pieces: perhaps Mr Davies' lyric gift cannot
find its most fitting expression in themes so grim: in any case it is
clear that these personal pieces are not equal to the lighter songs.
Now if one's conscience were supple enough to accept those lighter
songs as Mr Davies' complete work: if we could conveniently forget
the autobiography, and when visualizing his output, call up some
charming collected edition of the poems with the unsatisfactory ones
carefully deleted, we could go on with our study easily and gaily. We
might pause a moment to marvel at this 'isolated phenomenon': we
might even remark upon his detachment, not only from literature,
but almost as completely from the ordinary concerns of life. That
done, however, we should at once take a header into the delicious
refreshment of the lyrics. Such a study would be very fascinating;
and from the standpoint of Art as Art, it might not be inadequate.
But it would totally lack significance. Even from the point of view of
pure poetry, the loss would be profound—not to realize that behind
the blithest of these trills of song is a background as stormy as any
64. winter sky behind a robin on a bare bough. There is this one, for
example, from the volume called Foliage:
If I were gusty April now,
How I would blow at laughing Rose;
I'd make her ribbons slip their knots,
And all her hair come loose.
If I were merry April now,
How I would pelt her cheeks with showers;
I'd make carnations rich and warm,
Of her vermilion flowers.
Since she will laugh in April's face,
No matter how he rains or blows—
Then O that I wild April were,
To play with laughing Rose.
The gaiety of that, considered simply in its lightness of heart, its
verbal and metrical felicity, is a delightful thing. And it recurs so
frequently as to make Mr Davies quite the jolliest of modern poets.
So if we are content to stop there, if we are not teased by an
instinct to relate things, and see all round them, we may make
holiday pleasantly enough with this part of the poet's work. The
method is not really satisfying, however, and the inclusion of the
more personal pieces adds a deeper value to the study. Not merely
because the facts of a poet's life are interesting in themselves, but
because here especially they are illuminating, explanatory,
suggestive: connecting and unifying the philosophical interest of the
work, and supplying a background, curiously impressive, for its art.
For that reason one would refuse to pass over in silence Mr Davies'
first book of poems, The Soul's Destroyer, published in 1907. Not
that it is perfect poetry: indeed, I doubt whether one really
satisfying piece could be chosen from the whole fourteen. But it has
deep human interest. The book is slim, sombre, almost insignificant
in its paper wrappers. But its looks belie it. It is, in fact, nothing less
65. than a flame of courage, a shining triumph of the spirit of humanity.
Mr Shaw has made play with the facts of this poet's life, partly
because 'it is his nature so to do,' and partly, one suspects, to hide a
deeper feeling. But play as you will with the willing vagabondage,
the happy irresponsibility, the weakness and excess and error of a
wild youth, you will only film the surface of the tragedy. Underneath
will remain those sullen questions—what is life about, what are our
systems and our laws about, that a human creature and one with
the miraculous spark of genius in him, is chased hungry and
homeless up and down his own country, tossed from continent to
continent and thrown up at last, broken and all but helpless, to be
persecuted by some contemptible agent of charity and to wander
from one crowded lodging-house to another, seeking vainly for a
quiet corner in which to make his songs. The verses in The Soul's
Destroyer were written under those conditions; and by virtue of that
it would seem that the drab little volume attains to spiritual
magnificence.
The themes in this book and those of New Poems, published in the
same year, are of that personal kind of which we have already
spoken. But you will be quite wrong if you suppose that they are
therefore gloomy. On the contrary, though there is an occasional
didactic piece, like that which gives its title to the first volume, there
is more often a vein of humour. Thus we have the astonishing
catalogue of lodging-house humanity in Saints and Lodgers with
the satirical flavour of its invocation:
Ye saints, that sing in rooms above,
Do ye want souls to consecrate?
And there is The Jolly Tramp, a scrap of autobiography, perhaps
the least bit coloured:
I am a jolly tramp: I whine to you,
Then whistles till I meet another fool.
I call the labourer sir, the boy young man,
The maid young lady, and the mother I
66. Will flatter through the youngest child that walks.
In Wondering Brown there is surely something unique in poetry:
not alone in theme, and the extraordinary set of circumstances
which enabled such a bit of life to be observed, by a poet, from the
inside; but in the rare quality of it, its sympathetic satire, the genial
incisiveness of its criticism of life:
There came a man to sell his shirt,
A drunken man, in life low down;
When Riley, who was sitting near,
Made use of these strange words to Brown.
Yon fallen man, that's just gone past,
I knew in better days than these;
Three shillings he could make a day,
As an adept at picking peas.
.....
You'd scarcely credit it, I knew
A man in this same house, low down,
Who owns a fish-shop now—believe
Me, or believe me not, said Brown.
He was a civil sort of cove,
But did queer things, for one low down:
Oft have I watched him clean his teeth—
As true as Heaven's above! cried Brown.
This humorous quality is the most marked form of an attitude of
detachment which may be observed in most of the personal pieces.
So complete is this detachment sometimes, as in Strange People or
Scotty Bill or Facts, that one is tempted to a heresy. Is it
possible, in view of this lightness of touch, this untroubled pace and
coolness of word and phrase, that the poet did not see the
implications of what he was recording, or seeing them, was not
67. greatly moved by them? Now there are certain passages which
prove that that doubt is a heresy: that the poet did perceive and feel
the complete significance of the facts he was handling. Otherwise, of
course, he were no poet. There is evidence of this in such a poem as
A Blind Child, from which I quote a couple of stanzas:
We're in the garden, where are bees
And flowers, and birds, and butterflies;
There is one greedy fledgling cries
For all the food his parent sees!
I see them all: flowers of all kind,
The sheep and cattle on the leas;
The houses up the hills, and trees—
But I am dumb, for she is blind.
There is, too, the last stanza of Facts, a narrative piece which
relates the infamous treatment by workhouse officials of an old and
dying man:
Since Jesus came with mercy and love,
'Tis nineteen hundred years and five:
They made that dying man break stones,
In faith that Christ is still alive.
A hideous scrap of notoriety for A.D. 1905!—and proof enough to
convince us of our author's humanity. At the same time, however, it
is the fact that there is little sign of intense emotion in this work.
One comes near it, perhaps, in a passage in The Forsaken Dead,
where the poet is musing in the burial-place of a deserted
settlement, and breaks into wrath at the tyranny which drove the
people out:
Had they no dreamer who might have remained
To sing for them these desolated scenes?
One who might on a starvèd body take
Strong flights beyond the fiery larks in song,
68. With awful music, passionate with hate?
But that is a rare example. Deep emotion is not a feature of Mr
Davies' poetry: neither in the poems of life, which might be
supposed to awaken it directly; nor, stranger still, in the infrequent
love poems; nor in the lyrics of nature. It would be interesting to
speculate on this, if there were any use in it—whether it is after all
just a sign of excessive feeling, masked by restraint; whether it may
be in some way a reaction from a life of too much sensation; or
whether it simply means that emotion is nicely balanced by objective
power. Perhaps an analysis would determine the question in the
direction of a balance of power; but the fact remains that though
sensibility has a wide range, though it is quick, acute and tender, it is
not intense.
It would be unfair, however, to suggest that these earlier volumes
are only interesting on the personal side. The pure lyric note is
uttered first here: once or twice in a small perfect song, as The
Likeness and Parted; but oftener in a snatch or a broken trill, as
He who loves Nature truly, hath
His wealth in her kind hands; and it
Is in safe trust until his death,
Increasing as he uses it.
Or a passage from Music, invoking the memory of childhood:
O happy days of childhood, when
We taught shy Echo in the glen
Words she had never used before—
Ere Age lost heart to summon her.
Life's river, with its early rush,
Falls into a mysterious hush
When nearing the eternal sea:
Yet we would not forgetful be,
In these deep, silent days so wise,
Of shallows making mighty noise
69. When we were young, when we were gay,
And never thought Death lived—that day.
Or a fragment from The Calm, when the poet has been thinking of
his tempestuous past, and contrasts it with his present well-being,
and the country joys which he fears will be snatched away again:
But are these pleasant days to keep?
Where shall I be when Summer comes?
When, with a bee's mouth closed, she hums
Sounds not to wake, but soft and deep,
To make her pretty charges sleep?
The love of Nature which supplies the theme here is a characteristic
that persists throughout the subsequent volumes. It recurs more and
more frequently, until the autobiographical element is almost
eliminated; and just as it is the main motive of the later poetry, so it
is its happiest inspiration. It is rather a pagan feeling, taking great
joy in the beauty of the material world, revelling in the impressions
of sight and scent, sound and taste and touch. It is humane enough
to embrace the whole world of animal life; but it seeks no spirit
behind the phenomena of Nature, and cares precisely nothing about
its more scientific aspect. Its gay lightsomeness is a charming thing
to watch, an amazing thing to think about:
For Lord, how merry now am I!
Tickling with straw the butterfly,
Where she doth in her clean, white dress,
Sit on a green leaf, motionless,
To hear Bees hum away the hours.
Or again, from Leisure, in Songs of Joy:
What is this life if, full of care,
We have no time to stand and stare.
.....
70. No time to see, when woods we pass,
Where squirrels hide their nuts in grass.
No time to see, in broad daylight,
Streams full of stars, like skies at night.
.....
A poor life this if, full of care,
We have no time to stand and stare.
And a Greeting, from the volume called Foliage:
Good morning, Life—and all
Things glad and beautiful.
My pockets nothing hold,
But he that owns the gold,
The Sun, is my great friend—
His spending has no end.
Hail to the morning sky,
Which bright clouds measure high;
Hail to you birds whose throats
Would number leaves by notes;
Hail to you shady bowers,
And you green fields of flowers.
The poet does not claim to be learned in nature lore: indeed he
declares in one place that he does not know 'the barley from the
oats.' But he has a gift of fancy which often plays about his
observation with delightful effect. One could hardly call it by so big a
name as imagination: that suggests a height and power of vision
which this work does not possess, and which one would not look for
in this type of genius. It is a lighter quality, occasionally childlike in
its naïveté, fantastical, graceful, even quaint. It is seen in simile
sometimes, as this from The Soul's Destroyer, describing the sky:
It was a day of rest in heaven, which seemed
71. A blue grass field thick dotted with white tents
Which Life slept late in, though 'twere holiday.
Or this account of the origin of the Kingfisher, from Farewell to
Poesy:
It was the Rainbow gave thee birth,
And left thee all her lovely hues;
And, as her mother's name was Tears,
So runs it in thy blood to choose
For haunts the lonely pools, and keep
In company with trees that weep.
Or a fancy about the sound of rain from Nature Poems:
I hear leaves drinking rain;
I hear rich leaves on top
Giving the poor beneath
Drop after drop;
'Tis a sweet noise to hear
Those green leaves drinking near.
It plays an important part too in the poems upon other favourite
themes, on a woman's hair, on her voice, on music. Such are Sweet
Music and A Maiden and her Hair in Nature Poems: as well as
The Flood, from which I quote. It will be found in Songs of Joy:
I thought my true love slept;
Behind her chair I crept
And pulled out a long pin;
The golden flood came out,
She shook it all about,
With both our faces in.
Ah! little wren I know
Your mossy, small nest now
A windy, cold place is:
72. No eye can see my face,
Howe'er it watch the place
Where I half drown in bliss.
A development of technique in the later work lends ease and
precision to the poet's use of his instrument. Little faults of metre
and of rhyme are corrected: banalities of phrase and crudities of
thought almost disappear, so that the verse acquires a new grace. It
gains, too, from a wider variety of form: for the verses may be as
short as one foot, or as long as five: and there may be stanzas of
only two lines, or anything up to eight. There are even pieces
written in the closed couplet and in blank verse. But Mr Davies is by
no means an innovator in his art, as so many of his contemporaries
are. The variety we have noted is, after all, only a modification of
traditional form and not a departure from it; and always as its basis,
the almost constant unit is the iamb. Very rarely is any other
measure adopted; and so well does the iamb suit the simple and
direct nature of this work in thought, word and phrase, that one
would not often alter it. One of the perfect examples of its fitness is
in The Battle, from Nature Poems:
There was a battle in her face,
Between a Lily and a Rose:
My Love would have the Lily win
And I the Lily lose.
I saw with joy that strife, first one,
And then the other uppermost;
Until the Rose roused all its blood,
And then the Lily lost.
When she's alone, the Lily rules,
By her consent, without mistake:
But when I come that red Rose leaps
To battle for my sake.
73. Occasionally, however, and especially in the longer poems, the
regular recurrence of the iamb is a little monotonous. Then a wish
just peeps out that Mr Davies were more venturous: that he had
some slight experimental turn, or that he did not stand quite so far
aloof from the influences which, within his sight and hearing, are
shaping a new kind of poetic expression. But the regret may be put
aside. The fresh forms which those others are evolving are valid for
them—for life as they conceive it—for the wider range and the more
complex nature of the experience out of which they are distilling the
poetic essence. For him, however, the lyric mood burns clear and
untroubled, kindling directly to the beauty of simple and common
things. And instinctively he seeks to embody it in cadence and
measure which are sweetly familiar. When some exhilarating touch
quickens and lightens his verse with a more tripping measure, as in
The Laughers (from Nature Poems) its gay charm is irresistible.
Mary and Maud have met at the door,
Oh, now for a din; I told you so:
They're laughing at once with sweet, round mouths,
Laughing for what? does anyone know?
Is it known to the bird in the cage,
That shrieketh for joy his high top notes,
After a silence so long and grave—
What started at once those two sweet throats?
Is it known to the Wind that takes
Advantage at once and comes right in?
Is it known to the cock in the yard,
That crows—the cause of that merry din?
Is it known to the babe that he shouts?
Is it known to the old, purring cat?
Is it known to the dog, that he barks
For joy—what Mary and Maud laugh at?
74. Is it known to themselves? It is not,
But beware of their great shining eyes;
For Mary and Maud will soon, I swear,
Find cause to make far merrier cries.
It is hard to close even a slight study of Mr Davies' work without
another glance at his originality. One hesitates to use that word,
strained and tortured as it often is to express a dozen different
meanings. It might be applied, in one sense or another, to nearly all
our contemporary poets, with whom it seems to be an article of
artistic faith to avoid like the plague any sign of being derivative. So,
although their minds may be steeped in older poetry, they
deliberately turn away from its influence, seeking inspiration in life
itself. There is no doubt that they are building up a new kind of
poetry, with values that sound strange perhaps to the unfamiliar ear,
but which bid fair to enlarge the field for the poetic genius and
enrich it permanently. But the crux of the question for us at this
moment is the fact of effort, the deliberate endeavour which is made
by those poets to escape from tradition. No sign of such an effort is
visible in Mr Davies' work, and yet it is the most original of them all
—the newest, freshest, and most spontaneous.
The reason lies, of course, in the qualities we have already noted. It
is not entirely an external matter, as the influence of his career
might lead us to believe. That has naturally played its part, making
the substance of some of his verse almost unique; and, more
important still, guarding him from bookishness and leaving his mind
free to receive and convey impressions at first hand. From this come
the bracing freshness of his poetry, its naïveté of language, its
apparent artlessness and unconscious charm. But the root of the
matter lies deeper than that, mainly I think in the sincerity and
simplicity which are the chief qualities of his genius. Both qualities
are fundamental and constant, vitalizing the work and having a
visible influence upon its form. For, on the one hand, we see that
simplicity reflected not only in the thought, and themes, but in the
language and the technique of this poetry; while on the other hand
75. there is a loyalty which is absolutely faithful to its own experience
and the laws of its own nature.
76. Walter De La Mare
There is one sense in which this poet has never grown up, and we
may, if we please, recapture our own childhood as we wander with
him through his enchanted garden. And if it be true, as John
Masefield says, that the days that make us happy make us wise, it
is blessed wisdom that should be ours at the end of our ramble. For
see what a delightful place it is! Not one of your opulent, gorgeous
gardens, with insolently well-groomed lawns and beds that teem
with precious nurselings; but a much homelier region, and one of
more elusive and delicate charm. Boundaries there are, for order
and safe going, but they are hidden away in dancing foliage: and
there are leafy paths which seem to wind into infinity, and corners
where mystery lurks.
Some one is always sitting there,
In the little green orchard;
.....
When you are most alone,
All but the silence gone ...
Some one is waiting and watching there,
In the little green orchard.
Flowers grow in the sunny spaces, and all the wild things that
children love—primrose and pimpernel, darnel and thorn;
Teasle and tansy, meadowsweet,
Campion, toadflax, and rough hawksbit;
Brown bee orchis, and Peals of Bells;
Clover, burnet, and thyme....
77. It is mostly a shadowy place however, not chill and gloomy, but
arched with slender trees, through whose thin leafage slant the
warm fingers of the sun, picking out clear, quickly-moving patterns
upon the grass. The air is soft, the light is as mellow as a harvest
moon, and the sounds of the outer world are subdued almost to
silence. Nothing loud or strenuous disturbs the tranquility: only the
remote voices of happy children and friendly beasts and kind old
people. Wonder lives here, but not fear; smiles but not laughter;
tenderness but not passion. And the presiding genius of the spot is
the poet's Sleeping Cupid, sitting in the shade with his bare feet
deep in the grass and the dew slowly gathering upon his curls: a
cool and lovesome elf, softly dreaming of beauty in a quiet place.
So one might try to catch into tangible shape the spirit of this poetry,
only to realize the impossibility of doing anything of the kind. But
mere analysis would be equally futile; for the essence of it is as
subtle as air and as fluid as light; and one is finally compelled, in the
hope of conveying some impression of the nature of it, to fall back
upon comparison. It is a clumsy method however, frequently doing
violence to one or both of the poets compared; and even when used
discreetly, it often serves only to indicate a more or less obvious
point of resemblance. But we must take the risk of that for the
moment, and call out of memory the magical effect that is produced
upon the mind by the reading of Kubla Khan, or Christabel or
The Ancient Mariner. Very similar to that is the effect of Mr. de la
Mare's poetry. There is a difference, and its implications are
important; but the chief fact is that here, amongst this modern
poetry of so different an order, you find work which seems like a
lovely survival from the age of romance.
That is why one has the feeling that this poet has never grown up.
Partly from a natural inclination, and partly from a deliberate plan
(like that of Coleridge) to produce a certain kind of art, he has
created a faëry, twilight world, a world of wonder and fantasy, which
is the home of perpetual youth. He has never really lost that time
when, as a little boy, he says that he listened to Martha telling her
78. stories in the hazel glen. Martha, of 'the clear grey eyes' and the
'grave, small, lovely head' is surely a veritable handmaid of romance:
'Once ... once upon a time ...'
Like a dream you dream in the night,
Fairies and gnomes stole out
In the leaf-green light.
And her beauty far away
Would fade, as her voice ran on,
Till hazel and summer sun
And all were gone:—
All fordone and forgot;
And like clouds in the height of the sky,
Our hearts stood still in the hush
Of an age gone by.
That hush, invoking a sense of remoteness in space and time, lies
over all his work. It is as though, walking in the garden of this verse,
a child flitted lightly before us with a finger raised in a gesture of
silence. And it is not for nothing that his principal book is called The
Listeners. Footfalls are light, and voices soft, and the wind is gentle:
the noise of life is filtered to a whisper or a rustle or a sleepy
murmur. It is a device, of course, as we quickly see if we peer too
curiously at it: just a contrivance of the romantic artist to create
'atmosphere.' But it is so cunningly done that you never suspect the
contriving; and if you would gauge the skill of the poet in this
direction, you should note that he is able to produce the desired
effect in the broad light of day as well as in shadow and twilight. It
is a more difficult achievement, and much rarer. Evening is the time
that the poets generally choose to work this particular spell: though
moonlight or starlight, dawn, sunset, and almost any degree of
darkness will serve them. Sunlight alone, wide-eyed, penetrating and
inquisitive, is inimical to their purpose. Yet Mr de la Mare, in a poem
called The Sleeper, succeeds in spinning this hush of wondering
79. awe out of the full light of a summer day. A little girl (Ann, a
charming and familiar figure in this poetry: at once a symbol of
childhood and a very human child) runs into the house to her
mother, and finds her asleep in her chair. That is all the 'plot'; and it
would be hard to find an incident slighter, simpler and more
commonplace. But out of this homespun material the poet has
somehow conjured an eerie, brooding, impalpable presence which
steals upon us as it does upon the child in the quiet house until, like
her, we want to creep quickly out again.
A sense of the supernatural, that constant component of the
romantic temperament, is of the essence of this poetry. The
manifestation of it is something more than a trick of technique, for it
has its origin in the very nature of the poet's genius. In its simpler
and more direct expression, it seems to spring out of the fearful joy
which this type of mind experiences in contact with the strange and
weird. Again, as in The Witch, it may take the form of a bit of pure
fantasy, transmitting the fascination which has already seized the
poet with a lurking smile at its own absurdity. The opening stanzas
tell of a tired old witch who sits down to rest by a churchyard wall;
and who, in jerking off her pack of charms, breaks the cord and
spills them all out on the ground:
And out the dead came stumbling,
From every rift and crack,
Silent as moss, and plundered
The gaping pack.
They wish them, three times over,
Away they skip full soon:
Bat and Mole and Leveret,
Under the rising moon.
Owl and Newt and Nightjar:
They take their shapes and creep,
Silent as churchyard lichen,
While she squats asleep.
80. .....
Names may be writ; and mounds rise;
Purporting, Here be bones:
But empty is that churchyard
Of all save stones.
Owl and Newt and Nightjar,
Leveret, Bat and Mole
Haunt and call in the twilight,
Where she slept, poor soul.
But in its subtler forms the supernatural element of this poetry is
more complex and more potent. And it would seem to have a
definite relation to the poet's philosophy. Not that it is possible to
trace an outline of systematic thought in work like this, where every
constituent is milled and sifted to exquisite fineness and fused to
perfect unity. But if we follow up a hint here and there, and correlate
them with the author's prose fiction, we shall not be able to escape
the suggestion of a mystical basis to the elusive witchery of so many
of his poems. We shall see it to be rooted in an extreme
sensitiveness to what are called 'psychic' influences: a sensitiveness
through which he becomes, at one end of the scale, acutely aware
of the presence of a surrounding spirit world; and at the other,
deeply sympathetic and tender to subhuman creatures.
No crude claim is made on behalf of any mystical creed; and still less
would one violate the fragile and mysterious charm of a poem like
The Listeners by so-called interpretation. But placed beside The
Witch, it is clearly seen to treat the supernatural on a higher plane:
it is, indeed, a piece of rare and delicate symbolism. There is no
recourse to the ready appeal of the grotesque and the marvellous;
and although we find here all the 'machinery' of a sensational poem
in the older romantic manner—the great empty house standing
lonely in the forest, moonlight and silence, and a traveller knocking
unheeded at the door—it is a very subtle blending of those elements
which has gone to produce the peculiar effect of this piece. Twice
81. the traveller knocks, crying: Is there anybody there? but no answer
comes:
... only a host of phantom listeners
That dwelt in the lone house then
Stood listening in the quiet of the moonlight
To that voice from the world of men:
Stood thronging the faint moonbeams on the dark stair,
That goes down to the empty hall,
Hearkening in an air stirred and shaken
By the lonely Traveller's call.
And he felt in his heart their strangeness,
Their stillness answering his cry,
While his horse moved, cropping the dark turf,
'Neath the starred and leafy sky;
For he suddenly smote on the door, even
Louder, and lifted his head:—
'Tell them I came, and no one answered,
That I kept my word,' he said.
Running through the piece—and more clearly perceived when the
whole poem is read—is the thread of melancholy which is
inseparably woven into all the poet's work of this kind. And it, too,
was a gift of his fairy-godmother when he was born, light in texture
as a gossamer and spun out of the softest silk. Melancholy is almost
too big a word to fit the thing it is, for there is no gloom in it. It is
like the silvery, transparent cloud of thoughtfulness which passes for
a moment over a happy face; and it has something of the youthful
trick of playing with the idea of sadness. Hence come the early
studies of Imogen and Ophelia, where the poet is so much in
love with mournfulness that he revels in making perfect phrases
about it.
Can death haunt silence with a silver sound?
Can death, that hushes all music to a close,
Pluck one sweet wire scarce-audible that trembles,
82. As if a little child, called Purity,
Sang heedlessly on of his dear Imogen?
But even when this verse approaches a degree nearer to the reality
of pain it is still, as it were, a reflected emotion; and there is no
poignance in it. It is a winning echo of sorrowfulness, caught by one
who has the habit of turning back to listen and look. Thus the
studies of old age which we sometimes find here are drawn in the
true romantic manner, with a sunset halo about them, and lightly
shadowed by wistfulness and faint regret. And the thought of death,
when it is allowed to enter, comes as caressingly as sleep. The little
poem called All That's Past, where the poet is thinking of how far
down the roots of all things go, is only one example of many where
melancholy is toned to the faintest strain of pensive sweetness:
Very old are the woods;
And the buds that break
Out of the briar's boughs,
When March winds wake,
So old with their beauty are—
Oh, no man knows
Through what wild centuries
Roves back the rose.
.....
Very old are we men;
Our dreams are tales
Told in dim Eden
By Eve's nightingales;
We walk and whisper awhile,
But, the day gone by,
Silence and sleep like fields
Of amaranth lie.
So we might continue to cull passages which represent one aspect
or another of the specific quality of Mr de la Mare's poetry. The
83. choice is embarrassingly rich, for there is remarkable unity of tone
and technical perfection here. But there is a danger in the process,
especially with work of so fine a grain; and one feels bound to
repeat the warning that it is impossible to dissect its ultimate
essence in this way. We can only come back to our comparison, and
recalling the magical music of poems like Arabia, Queen Djenira,
or Voices—in which all the characteristics noted are so intimately
blended that it is impossible to disengage them—reiterate the fact
that they possess the same inexplicable charm as the romantic work
of Coleridge.
But that reminds us of the difference, and all that it implies. For,
after all, this poet is a romanticist of the twentieth century, and not
of the late eighteenth. It is true that his genius has surprisingly kept
its youth (even more, that is to say, than the poet usually does); but
it is a nonage which is clearly of this time and no other. The signs of
this are clear enough. First and foremost, there is his humanity—in
which perhaps all the others are included, and with which are
certainly associated the simplicity and sincerity of his diction. It is as
though the two famous principles on which the Lyrical Ballads were
planned had in the fulness of time become united in the creative
impulse of a single mind. That is not to charge Mr de la Mare with
the combined weight of those two earlier giants, of course, but
simply to observe the truth which Rupert Brooke expressed so finely
when he said that the poetic spirit was coming back to its wider
home, the human heart. So that even a born romanticist like this
cannot escape; and into the chilly enchantment of an older manner
warm sunlight streams and fresh airs blow.
Obvious links with the life-movement of his time are not lacking,
though as mere external evidence they are relatively unimportant.
Of such are the synthesis of poetry and science in The Happy
Encounter; and the detachment suggested in Keep Innocency,
where the poet reveals a full consciousness of the gulf between
romance and reality. But the influence goes deeper than that. It is
because he is a child of his age that he has observed children so
lovingly, and has wrought child-psychology into his verse with such
84. wonderful accuracy. That also is why he calls so gently out of 'thin-
strewn memory' such a homely figure as the shy old maid in her old-
fashioned parlour; and thence, too, comes the sympathy with toiling
folk—considering them characteristically in the serene mood when
their work is done—which underlies such pieces as Old Susan and
Old Ben:
Sad is old Ben Thistlewaite,
Now his day is done,
And all his children
Far away are gone.
He sits beneath his jasmined porch,
His stick between his knees,
His eyes fixed vacant
On his moss-grown trees.
.....
But as in pale high autumn skies
The swallows float and play,
His restless thoughts pass to and fro,
But nowhere stay.
Soft, on the morrow, they are gone;
His garden then will be
Denser and shadier and greener,
Greener the moss-grown tree.
From the same humane temper come the poet's kindly feeling for
animals and his affectionate understanding of them. Over and over
again its positive aspect finds expression, either quaint, comical or
tender. And twice at least the negative side of it appears, coming as
near to rage at the wanton destruction of animal life as so mellow
and balanced a nature would ever get. It is a significant fact that at
such moments he takes refuge in his humour—that humour, at once
rich and delicate, which is perhaps the most precious quality of this
85. poetry, and which, growing from a free and sympathetic contact with
life, holds the scale counterpoised to a nicety against the glamorous
romantic sense. Thus we have this scrap of verse, lightly throwing
off a mood of disgust in whimsical idiom:
I can't abear a Butcher,
I can't abide his meat,
The ugliest shop of all is his,
The ugliest in the street;
Bakers' are warm, cobblers' dark,
Chemists' burn watery lights;
But oh, the sawdust butcher's shop,
That ugliest of sights!
And thus in Tit for Tat we find this apostrophe to a certain Tom
Noddy, just returning from a day of 'sport' with his gun over his
shoulder:
Wonder I very much do, Tom Noddy,
If ever, when you are a-roam,
An Ogre from space will stoop a lean face,
And lug you home:
Lug you home over his fence, Tom Noddy,
Of thorn-stocks nine yards high,
With your bent knees strung round his old iron gun
And your head dan-dangling by:
And hang you up stiff on a hook, Tom Noddy,
From a stone-cold pantry shelf,
Whence your eyes will glare in an empty stare,
Till you are cooked yourself!
The humour there, corresponding in degree to the indignation for
which it is a veil, is relatively broad. There are many subtler forms of
it, however, and one will be found in a charming piece which is apt
to our present point. It is called Nicholas Nye, and tells about an
86. old donkey in an orchard. He is an unprepossessing creature, lame
and worn-out: just a bit of animal jettison, thrown away here to end
his days in peace. And the poet had a great friendship with him:
But a wonderful gumption was under his skin,
And a clear calm light in his eye,
And once in a while: he'd smile:—
Would Nicholas Nye.
Seem to be smiling at me, he would,
From his bush in the corner, of may,—
Bony and ownerless, widowed and worn,
Knobble-kneed, lonely and grey;
And over the grass would seem to pass
'Neath the deep dark blue of the sky,
Something much better than words between me
And Nicholas Nye.
87. Wilfrid Wilson Gibson
There are a dozen books by this author, the work of about a dozen
years. They began to appear in 1902; and they end, so far as the
present survey is concerned, with poems that were published in the
first half of 1914. They make a good pile, a considerable
achievement in bulk alone; and when they are read in sequence,
they are found to represent a growing period in the poet's mind and
art which corresponds to, and epitomises, the transition stage out of
which English poetry is just passing. That is to say, in addition to the
growth that one would expect—the ripening and development which
would seem to be a normal process—there has occurred an
unexpected thing: a complete change of ideal, with steady and rapid
progress in the new direction. So that if Mr. Gibson's later books
were compared directly with the early ones, they might appear to be
by an entirely different hand. Place Urlyn the Harper—which was
first published—beside a late play called Womenkind or a still more
recent dramatic piece called Bloodybush Edge; and the contrast will
be complete. On the one hand there is all the charm of romance, in
material and in manner—but very little else. On the other hand there
is nothing to which the word charm will strictly apply; an almost
complete artistic austerity: but a profound and powerful study of
human nature. On the one hand there is a dainty lyrical form
appropriate to the theme: there are songs like this one, about the
hopeless love of the minstrel for the young queen who is mated with
an old harsh king:
I sang of lovers, and she praised my song,
The while the King looked on her with cold eyes,
And 'twixt them on the throne sat mailèd wrong.
88. I sang of Launcelot and Guenevere,
While in her face I saw old sorrows rise,
And throned between them cowered naked Fear.
I sang of Tristram and La Belle Isoud,
And how they fled the anger of King Mark
To live and love, deep sheltered in a wood.
Then bending low, she spake sad voiced and sweet,
The while grey terror crouched between them stark,
Sing now of Aucassin and Nicolete.
The later work cannot be so readily illustrated: it is at once subtler
and stronger, and depends more upon the effect of the whole than
upon any single part. But for the sake of the contrast we may wrest
a short passage out of its setting in Bloodybush Edge. A couple of
tramps have met at night on the Scottish border; one is a cockney
Londoner, a bad lot with something sinister about him and a touch of
mystery. He has just stumbled out of the heather on to the road,
cursing the darkness and the loneliness of the moor. The other, a
Border man to whom night is beautiful and the wild landscape a
familiar friend, protests that it is not dark, that the sky is 'all alive
with little stars':
Tramp. ... Stars!
Give me the lamps along the Old Kent Road;
And I'm content to leave the stars to you.
They're well enough; but hung a trifle high
For walking with clean boots. Now a lamp or so....
Dick. If it's so fine and brave, the Old Kent Road,
How is it you came to leave it?
Tramp. ... I'd my reasons ...
But I was scared: the loneliness and all;
The quietness, and the queer creepy noises;
And something that I couldn't put a name to,
89. A kind of feeling in my marrow-bones,
As though the great black hills against the sky
Had come alive about me in the night,
And they were watching me; as though I stood
Naked, in a big room, with blind men sitting,
Unseen, all round me, in the quiet darkness,
That was not dark to them. And all the stars
Were eyeing me; and whisperings in the heather
Were like cold water trickling down my spine:
Putting an early and a late book side by side in this way, the contrast
is astonishing. And it is not an unfair method of comparison,
because when the new ideal appears it strikes suddenly into the
work, and sharply differentiates it at once from all that had been
written before. Like the larger movement which it so aptly illustrates,
the change is conscious, deliberate, and full of significance; and it is
the cardinal fact in this author's poetical career. It marks the stage at
which he came to grips with reality: when he brought his art into
relation with life: when the making of poetic beauty as an end in
itself could no longer content him; and the social conscience, already
prompting contemporary thought, quickened in him too.
Humanity was the new ideal: humanity at bay and splendidly
fighting. It appeared first in the two volumes of 1907 as dramatic
studies from the lives of shepherd-folk. Four books had preceded
these, in which the texture of the verse was woven of old romance
and legend. Another book was yet to come, The Web of Life, in
which the prettiness of that kind of romanticism would blossom into
absolute beauty. But the new impulse grew from the date of
Stonefolds; and when the first part of Daily Bread appeared, the
impulse had become a reasoned principle. In the poem which
prefaces that volume it comes alive, realizing itself and finding
utterance in terms which express much more than an individual
experience. I quote it for that reason. The immediate thought has
dignity and the personal note is engaging. There is, too, peculiar
interest in the clarity and precision with which it speaks, albeit
unconsciously, for the changing spirit in English poetry. But the final
90. measure of the poem is the touch of universality that is latent within
it. For here we have the expression of not only a law of development
by which the poet must be bound, and not only a poetical synthesis
of the most important intellectual movement of this generation, but
an experience through which every soul must pass, if and when it
claims its birthright in the human family.
As one, at midnight, wakened by the call
Of golden-plovers in their seaward flight,
Who lies and listens, as the clear notes fall
Through tingling silence of the frosty night—
Who lies and listens, till the last note fails,
And then, in fancy, faring with the flock
Far over slumbering hills and dreaming dales,
Soon hears the surges break on reef and rock;
And, hearkening, till all sense of self is drowned
Within the mightier music of the deep,
No more remembers the sweet piping sound
That startled him from dull, undreaming sleep:
So I, first waking from oblivion, heard,
With heart that kindled to the call of song,
The voice of young life, fluting like a bird,
And echoed that light lilting; till, ere long,
Lured onward by that happy, singing-flight,
I caught the stormy summons of the sea,
And dared the restless deeps that, day and night,
Surge with the life-song of humanity.
Being wise after the event, one can discover auguries of that change
in the very early work. There is, for example, a group of little poems
called Faring South, studied directly from peasant life in the south of
France. They indicate that even at that time an awakening sympathy
with toiling folk had begun to guide his observation; and they are in
any case a very different record of European travel from that of the
mere poetaster. There are studies of a stonebreaker, a thresher, a
ploughman; there is a veracious little picture of a housemother,
91. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com