100% found this document useful (7 votes)
147 views

C Programming Data Structures 4th Edition E. Balagurusamy 2024 Scribd Download

ebook

Uploaded by

josonibis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (7 votes)
147 views

C Programming Data Structures 4th Edition E. Balagurusamy 2024 Scribd Download

ebook

Uploaded by

josonibis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

Full download ebook at ebookgate.

com

C Programming Data Structures 4th Edition E.


Balagurusamy

https://ebookgate.com/product/c-programming-data-
structures-4th-edition-e-balagurusamy/

Download more ebook from https://ebookgate.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Programming in ANSI C 6th Edition E. Balagurusamy

https://ebookgate.com/product/programming-in-ansi-c-6th-edition-
e-balagurusamy/

Computer Programming 1st Edition E. Balagurusamy

https://ebookgate.com/product/computer-programming-1st-edition-e-
balagurusamy/

C Programming Program design including data structures


5ed. Edition Malik D.S.

https://ebookgate.com/product/c-programming-program-design-
including-data-structures-5ed-edition-malik-d-s/

Data Structures and Algorithms in C 4th Edition Adam


Drozdek

https://ebookgate.com/product/data-structures-and-algorithms-
in-c-4th-edition-adam-drozdek/
C Programming Program Design Including Data Structures
7th Edition D. S. Malik

https://ebookgate.com/product/c-programming-program-design-
including-data-structures-7th-edition-d-s-malik/

C Programming Program Design Including Data Structures


6th Edition D. S. Malik

https://ebookgate.com/product/c-programming-program-design-
including-data-structures-6th-edition-d-s-malik/

Data Structures and Other Objects Using C 4th Edition


Michael Main

https://ebookgate.com/product/data-structures-and-other-objects-
using-c-4th-edition-michael-main/

Data Structures Using C 2nd Edition D. S. Malik

https://ebookgate.com/product/data-structures-using-c-2nd-
edition-d-s-malik/

Data Structures Other Objects using Java 4th Edition


Michael Mann

https://ebookgate.com/product/data-structures-other-objects-
using-java-4th-edition-michael-mann/
As per the
Revised
Syllabus Effective
August 2007

C Programming
and
Data Structures
Fourth Edition
About the Author
E Balagurusamy, former Vice Chancellor, Anna University, Chennai, is currently Member, Union
Public Service Commission, New Delhi. He is a teacher, trainer, and consultant in the fields of Informa-
tion Technology and Management. He holds an ME (Hons) in Electrical Engineering and Ph.D in
Systems Engineering from the Indian Institute of Technology, Roorkee. His areas of interest include
Object-Oriented Software Engineering, Electronic Business, Technology Management, Business
Process Re-engineering, and Total Quality Management.
A prolific writer, he has authored a large number of research papers and several books. His best
selling books, among others include:
· Programming in C#, 2/e
· Programming in Java, 3/e
· Object-Oriented Programming with C++, 4/e
· Programming in BASIC, 3/e
· Programming in ANSI C, 4/e
· Numerical Methods
· Reliability Engineering
A recipient of numerous honours and awards, he has been listed in the Directory of Who’s Who of
Intellectuals and in the Directory of Distinguished Leaders in Education.
As per the
Revised
Syllabus Effective
August 2007

C Programming
and
Data Structures
Fourth Edition

E Balagurusamy
Member, UPSC
New Delhi

Tata McGraw-Hill Publishing Company Limited


NEW DELHI
McGraw-Hill Offices
New Delhi New York St Louis San Francisco Auckland Bogotá Caracas
Kuala Lumpur Lisbon London Madrid Mexico City Milan Montreal
San Juan Santiago Singapore Sydney Tokyo Toronto
Published by the Tata McGraw-Hill Publishing Company Limited,
7 West Patel Nagar, New Delhi 110 008.

Copyright © 2009, by Tata McGraw-Hill Publishing Company Limited.


No part of this publication may be reproduced or distributed in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise or stored in a database or retrieval system without the prior written permis-
sion of the publishers. The program listings (if any) may be entered, stored and executed in a computer system, but
they may not be reproduced for publication.
This edition can be exported from India only by the publishers,
Tata McGraw-Hill Publishing Company Limited.
ISBN-13: 978-0-07-0084759
ISBN-10: 0-07-0084750
Managing Director—Ajay Shukla
General Manager: Publishing—SEM & Tech Ed: Vibha Mahajan
Sponsoring Editor—Shalini Jha
Senior Copy Editor—Dipika Dey
Junior Manager—Production, Anjali Razdan
Marketing General Manager—Higher Education & Sales: Michael J. Cruz
Product Manager—SEM & Tech Ed: Biju Ganesan
Controller—Production: Rajender P. Ghansela
Asst. General Manager— Production: B. L. Dogra

Information contained in this work has been obtained by Tata McGraw-Hill, from sources believed to be
reliable. However, neither Tata McGraw-Hill nor its authors guarantee the accuracy or completeness of any
information published herein, and neither Tata McGraw-Hill nor its authors shall be responsible for any
errors, omissions, or damages arising out of use of this information. This work is published with the under-
standing that Tata McGraw-Hill and its authors are supplying information but are not attempting to render
engineering or other professional services. If such services are required, the assistance of an appropriate
professional should be sought.

Typeset at Script Makers, 19, A1-B, DDA Market, Paschim Vihar, New Delhi 110 063, and printed at Shakti
Packers, 5C/9, New Rohtak Road, Karol Bagh, New Delhi-110 005
Cover: SDR Printers
DALZCRBFRAALX
Contents

Foreword xi
Preface xiii
Road Map to the Syllabus xv
The C99 Standard xvii

UNIT I
1. Algorithms 1.3–1.15
1.1 Introduction ......................................................................................................................... 1.3
1.1.1 Algorithm/pseudocode .......................................................................................... 1.3
1.1.2 Flow Chart............................................................................................................ 1.4
1.2 Three Basic Operations ....................................................................................................... 1.5
1.2.1 Sequence .............................................................................................................. 1.5
1.2.2 Selection ............................................................................................................... 1.6
1.2.3 Iteration .............................................................................................................. 1.13
Review Questions and Exercises ..................................................................................... 1.14
2. Overview of C 2.1–2.12
2.1 Introduction ......................................................................................................................... 2.1
2.2 Importance of C .................................................................................................................. 2.1
2.3 Sample C Programs ............................................................................................................. 2.2
2.4 Program Development Steps ............................................................................................... 2.5
2.5 Structure of a C Program .................................................................................................... 2.9
Review Questions and Exercises ..................................................................................... 2.11
3. Constants, Variables, and Data Types 3.1–3.26
3.1 Introduction ........................................................................................................................ .3.1
3.2 Character Set ....................................................................................................................... 3.1
3.3 C Tokens ............................................................................................................................. 3.1
3.4 Keywords and Identifiers .................................................................................................... 3.2
3.5 Constants ............................................................................................................................. 3.3
3.6 Variables ............................................................................................................................. 3.7
3.7 Basic Data Types and Sizes ................................................................................................ 3.8
3.8 Declaration of Variables ................................................................................................... 3.11
3.9 Assigning Values to Variables .......................................................................................... 3.14
3.10 Defining Symbolic Constants ........................................................................................... 3.21
Review Questions and Exercises ................................................................................... 3.24
vi Contents
4. Operators and Expressions 4.1–4.22
4.1 Introduction ......................................................................................................................... 4.1
4.2 Arithmetic Operators .......................................................................................................... 4.1
4.3 Relational Operators ........................................................................................................... 4.4
4.4 Logical Operators ............................................................................................................... 4.5
4.5 Assignment Operators ......................................................................................................... 4.5
4.6 Increment and Decrement Operators .................................................................................. 4.7
4.7 Conditional Operator .......................................................................................................... 4.8
4.8 Bitwise Operators ............................................................................................................... 4.8
4.9 Special Operators ................................................................................................................ 4.9
4.10 Arithmetic Expressions ..................................................................................................... 4.11
4.11 Evaluation of Expressions ................................................................................................ 4.11
4.12 Precedence of Arithmetic Operators ................................................................................. 4.12
4.13 Some Computational Problems ......................................................................................... 4.14
4.14 Type Conversions in Expressions ..................................................................................... 4.15
4.15 Operator Precedence and Associativity ............................................................................ 4.18
Case Studies ..................................................................................................................... 4.19
Review Questions and Exercises ..................................................................................... 4.20
5. Managing Input and Output Operations 5.1–5.25
5.1 Introduction ......................................................................................................................... 5.1
5.1.1 Input/Output Statements and Header Files ........................................................... 5.1
5.2 Reading a Character ............................................................................................................ 5.2
5.3 Writing a Character ............................................................................................................ 5.4
5.4 Formatted Input ................................................................................................................... 5.5
5.5 Formatted Output .............................................................................................................. 5.14
Case Studies ..................................................................................................................... 5.21
Review Questions and Exercises ..................................................................................... 5.24
6. Decision Making and Branching 6.1–6.29
6.1 Introduction ......................................................................................................................... 6.1
6.2 Decision Making with If Statement .................................................................................... 6.1
6.3 Simple If Statement ............................................................................................................. 6.2
6.4 The If K Else Statement ..................................................................................................... 6.5
6.5 Nesting of If ... Else Statements .......................................................................................... 6.7
6.6 The Else If Ladder ............................................................................................................ 6.11
6.7 The Switch and Break Statements .................................................................................... 6.13
6.8 The ? : Operator ................................................................................................................ 6.17
6.9 The Goto Statement .......................................................................................................... 6.20
6.9.1 Label .................................................................................................................. 6.20
Case Studies ..................................................................................................................... 6.22
Review Questions and Exercises ..................................................................................... 6.26
7. Decision Making and Looping 7.1–7.30
7.1 Introduction ......................................................................................................................... 7.1
7.2 The While Statement ........................................................................................................... 7.3
7.3 The Do Statement ................................................................................................................ 7.4
Contents vii
7.4 The For Statement ............................................................................................................... 7.6
7.5 Jumps in Loops ................................................................................................................. 7.14
7.6 Structured Programming ................................................................................................... 7.20
Case Studies ..................................................................................................................... 7.21
Review Questions and Exercises ..................................................................................... 7.27

UNIT II

8. Arrays 8.3–8.31
8.1 Introduction ......................................................................................................................... 8.3
8.2 One-Dimensional Arrays .................................................................................................... 8.3
8.3 Two-Dimensional Arrays.................................................................................................... 8.8
8.4 Initializing Two-Dimensional Arrays ............................................................................... 8.13
8.5 Multidimensional Arrays .................................................................................................. 8.15
Case Studies ..................................................................................................................... 8.17
Review Questions and Exercises ..................................................................................... 8.28
9. Handling of Character Strings 9.1–9.23
9.1 Introduction ......................................................................................................................... 9.1
9.2 Declaring and Initializing String Variables ........................................................................ 9.2
9.3 Reading Strings from Terminal ........................................................................................... 9.2
9.4 Writing Strings to Screen .................................................................................................... 9.5
9.5 Arithmetic Operations on Characters ................................................................................. 9.8
9.6 Putting Strings Together ................................................................................................... 9.10
9.7 Comparison of Two Strings .............................................................................................. 9.12
9.8 String-Handling Functions ................................................................................................ 9.13
9.9 Table of Strings ................................................................................................................. 9.15
Case Studies ..................................................................................................................... 9.18
Review Questions and Exercises ..................................................................................... 9.22
10. User-Defined Functions 10.1–10.50
10.1 Introduction ....................................................................................................................... 10.1
10.1.1 Standard Library Functions ................................................................................ 10.1
10.2 Need for User-Defined Functions ..................................................................................... 10.4
10.3 A Multi-Function Program ................................................................................................ 10.5
10.4 The Form of C Functions .................................................................................................. 10.7
10.5 Return Values and their Types .......................................................................................... 10.8
10.6 Calling a Function ............................................................................................................. 10.9
10.7 Category of Functions ..................................................................................................... 10.10
10.8 No Arguments and no Return Values ............................................................................. 10.10
10.9 Arguments but no Return Values .................................................................................... 10.12
10.10 Arguments with Return Values ....................................................................................... 10.14
10.11 Handling of Non-Integer Functions ................................................................................ 10.18
10.12 Nesting of Functions ....................................................................................................... 10.21
10.13 Recursion ........................................................................................................................ 10.22
10.14 Functions with Arrays ..................................................................................................... 10.23
10.15 The Scope and Lifetime of Variables in Functions—Storage Classes ............................ 10.26
viii Contents
10.16 ANSI C Functions ........................................................................................................... 10.36
10.17 The Preprocessor ............................................................................................................. 10.39
10.18 ANSI Additions .............................................................................................................. 10.42
Case Study ...................................................................................................................... 10.45
Review Questions and Exercises ................................................................................. 10.49

UNIT III

11. Pointers 11.3–11.32


11.1 Introduction ....................................................................................................................... 11.3
11.2 Understanding Pointers ..................................................................................................... 11.3
11.3 Accessing the Address of a Variable ................................................................................ 11.5
11.4 Declaring and Initializing Pointers ................................................................................... 11.6
11.5 Accessing a Variable Through its Pointer ........................................................................ 11.7
11.6 Pointer Expressions .......................................................................................................... 11.9
11.7 Pointer Increments and Scale Factor—Address Arithmetic ............................................ 11.11
11.8 Pointers and Arrays......................................................................................................... 11.12
11.9 Pointers and Character Strings ........................................................................................ 11.15
11.10 Pointers and Functions .................................................................................................... 11.17
11.11 Pointers and Structures ................................................................................................... 11.23
Case Studies ................................................................................................................... 11.25
Review Questions and Exercises ................................................................................... 11.31

UNIT IV

12. Structures and Unions 12.3–12.25


12.1 Introduction ....................................................................................................................... 12.3
12.2 Structure Definition—Declaring Structures ..................................................................... 12.3
12.3 Giving Values to Members ............................................................................................... 12.5
12.4 Structure Initialization ...................................................................................................... 12.6
12.5 Comparison of Structure Variables ................................................................................... 12.8
12.6 Arrays of Structures .......................................................................................................... 12.8
12.7 Arrays within Structures ................................................................................................. 12.11
12.8 Structures within Structures—Nested Structures ............................................................ 12.12
12.9 Structures and Functions ................................................................................................. 12.15
12.10 Unions ............................................................................................................................. 12.17
12.11 Size of Structures ............................................................................................................ 12.19
12.12 Bit Fields ......................................................................................................................... 12.19
Case Study ...................................................................................................................... 12.21
Review Questions and Exercises ................................................................................. 12.24

UNIT V

13. File Management in C 13.3–13.22


13.1 Introduction ....................................................................................................................... 13.3
13.2 Defining and Opening a File ............................................................................................. 13.7
Contents ix
13.3 Closing a File .................................................................................................................... 13.8
13.4 Input/Output Operations on Files ...................................................................................... 13.9
13.5 Error Handling During I/O Operations ........................................................................... 13.12
13.6 Random Access to Files .................................................................................................. 13.14
13.7 Command Line Arguments ............................................................................................. 13.17
Case Study ...................................................................................................................... 13.19
Review Questions and Exercises ................................................................................... 13.21

UNIT VI

14. Data Structures 14.3–14.21


14.1 Introduction to Data Structures ......................................................................................... 14.3
14.2 Stacks ................................................................................................................................ 14.3
14.3 Queues .............................................................................................................................. 14.6
14.4 Circular Queues .............................................................................................................. 14.10
14.5 Applications of Stacks .................................................................................................... 14.11
Review Questions and Exercises ................................................................................... 14.21

UNIT VII

15. Dynamic Memory Allocation and Linked Lists 15.3–15.47


15.1 Introduction ....................................................................................................................... 15.3
15.2 Dynamic Memory Allocation ............................................................................................ 15.3
15.3 Linked Lists ...................................................................................................................... 15.9
15.3.1 Self-Referential Structure .................................................................................. 15.9
15.3.2 Singly Linked List ............................................................................................ 15.10
15.4 Advantages of Linked Lists ............................................................................................ 15.12
15.5 Types of Linked Lists...................................................................................................... 15.12
15.6 Pointers Revisited ........................................................................................................... 15.14
15.7 Basic List Operations...................................................................................................... 15.15
15.8 Application of Linked Lists ............................................................................................ 15.24
15.9 Circular Linked Lists ...................................................................................................... 15.25
15.10 Doubly Linked Lists ....................................................................................................... 15.25
15.11 Doubly Linked List Operations ...................................................................................... 15.26
15.12 Doubly Linked Circular Lists ......................................................................................... 15.35
15.13 Stacks and Queues using Linked List ............................................................................. 15.36
Case Studies ................................................................................................................... 15.40
Review Questions and Exercises ................................................................................... 15.46
16. Binary Trees and Graphs 16.1–16.25
16.1 Binary Trees—Representation and Terminology .............................................................. 16.1
16.2 Binary Tree Traversal ....................................................................................................... 16.2
16.3 Graphs ............................................................................................................................... 16.8
16.4 Graph Representation in C ................................................................................................ 16.9
16.5 Graph Traversal .............................................................................................................. 16.13
Review Questions and Exercises ................................................................................. 16.24
x Contents

UNIT VIII

17. Sorting and Searching Techniques 17.3–17.25


17.1 Introduction ....................................................................................................................... 17.3
17.2 Sorting ............................................................................................................................... 17.3
17.2.1 Sorting Efficiency .............................................................................................. 17.4
17.2.2 Exchange Sorting—Bubble Sort ........................................................................ 17.5
17.2.3 Exchange Sorting—Quick Sort .......................................................................... 17.7
17.2.4 Selection Sort ................................................................................................... 17.11
17.2.5 Merge Sort........................................................................................................ 17.13
17.2.6 Simple Insertion sort ........................................................................................ 17.15
17.2.7 Shell Sort .......................................................................................................... 17.17
17.3 Searching ........................................................................................................................ 17.18
17.3.1 Linear Search ................................................................................................... 17.18
17.3.2 Binary Search ................................................................................................... 17.20
17.3.3 Indexed Sequential Search ............................................................................... 17.23
Review Questions ........................................................................................................... 17.24
Appendix A
ASCII Values of Characters .......................................................................................A.1
Appendix B
Multiple Choice Questions .............................................................................. B.1–B.9
Appendix C
Solved Question Papers – C Programming and Data Structures
(May/June 2008) ............................................................................................... C.1–C.76
Bibliography .......................................................................................................................B.1
Chapter
1
Foreword

It gives me great pleasure to introduce C Programming and Data Structures by Dr E Balagurusamy,


publication of which heralds the completion of a book that caters completely and effectively to the
students of JNTU.
The need for a good textbook for this subject can be easily understood. Numerous books are available
to the students for the subject, but almost none of them have the right combination of simplicity, rigour,
pedagogy and syllabus compatibility. These books usually do not address one or more of the specific
problems faced by students of this subject in JNTU. There has always been a need for a good book
relevant to the requirements of the students and dealing with all aspects of the course. I am sure that the
present book will be able to fill this void.
The book has been organized and executed with lot of care and dedication. The author has been an
outstanding teacher and a pioneer of IT education in India. A conscious attempt has been made to
simplify concepts to facilitate better understanding of the subject.
Dr Balagurusamy deserves our praise and thanks for accomplishing this trying task. McGraw-Hill
Education, a prestigious publishing house, also deserves a pat on the back for doing an excellent job.

DR K. RAJAGOPAL
Vice-Chancellor
Jawaharlal Nehru Technological University
Hyderabad
Chapter
1
Preface

C is a general-purpose structured programming language that is powerful, efficient and compact. C


combines the features of high-level language with the elements of the assembler and is thus close to both
man and machine. The growth of C during the last few years has been phenomenal. It has emerged as the
language of choice for most applications due to speed, portability and compactness of code. It has now
been implemented on virtually every sort of computer, from micro to mainframe.
For many years, the de facto standard for implementing the language has been the original C Refer-
ence Manual by Kernighan and Ritchie published in 1978. During these years of growth and popularity,
C has undergone many changes. Numerous different features and facilities have been developed and
marketed. This has resulted in minor problems in terms of portability of programs. Consequently, the
American National Standard Institute (ANSI) constituted a committee to look into the language features
and produce a more comprehensive and unambiguous definition of C. The result is ANSI C. Most com-
pilers have already adopted ANSI standards.
This book incorporates all the features of ANSI C that are essential for a C programmer. The ANSI
standards are explained in detail in appropriate places. For the convenience of readers, these places
have been noted in the text by a special mention. A major highlight of this revised edition is the
inclusion of updated information on compiler C99 standard, with relevant theory and programs.
Another important addition in this edition is Appendix C containing 2008 solved question papers (4 sets).
The concept of ‘learning by example’ has been stressed throughout the book. Every important feature of
the language is treated in depth followed by a complete program example to illustrate its use. Case studies
at the end of the chapters not only describe the common ways in which C features are put together but
also show real-life applications. Wherever necessary, pictorial descriptions of concepts are included to
facilitate better understanding.
This book contains more than 100 examples and programs. All the programs have been tested using
compilers compatible to both UNIX and MS-DOS operating systems and, wherever appropriate, the
nature of output has been discussed. These programs also demonstrate the general principles of a good
programming style. 200 multiple choice questions are given to help the students test their conceptual
understanding of the subject.
The book also offers detailed discussions on Data Structures, Standard Library Functions,
Bit Fields, Linked Lists, Doubly Linked Lists, Queues, Stacks and Graphs with sample codes and
algorithms. Chapter 17 provides comprehensive information on Sorting and Searching techniques. Both
these topics are explained with sample codes. The various pros and cons of each of these techniques are
also covered.
xiv Preface
This edition comes with a CD which provides
More than 600 objective/review/debugging questions (8 units)
100 Programming exercises
Model question paper
2006 and 2007 solved question paper
Computer programs for lab
The objective of the supplementry CD is to make the students learn the programming language and
enable them to write their own programs using C and data structures.
The author is grateful to Mr A Rama Rao, Layola Institute of Technology & Management, Guntur
and Mr P Chenna Reddy, JNTU College of Engineering, Pulivendula for their useful comments and
suggestions.

E BALAGURUSAMY
Chapter
1
Road Map to the Syllabus
(Effective from August 2007)

Jawaharlal Nehru Technological University Hyderabad


I Year B.Tech T P C
4 0 6
C Programming and Data Structures
Objectives
· To make the student learn a programming language.
· To teach the student to write programs in C to solve the problems.
· To introduce the student to simple linear and non-liner data structures such as lists, stacks,
queues, trees and graphs.
Syllabus
Unit I
Algorithm / pseudo code, flowchart, program development steps, structure of C program, a simple C
program, identifiers, basic data types and sizes, constants, variables, arithmetic, relational and logical
operators, increment and decrement operators, conditional operator, bit-wise operators, assignment
operators, expressions, type conversions, conditional expressions, precedence and order of evaluation.
Input-output statements, statements and blocks, if and switch statements, loops- while, do-while and
for statements, break, continue, goto and labels, programming examples.

CHAPTER 1 – ALGORITHMS
CHAPTER 2 – OVERVIEW OF C
CHAPTER 3 – CONSTANTS, VARIABLES, AND DATA TYPES
Go To CHAPTER 4 – OPERATORS AND EXPRESSIONS
CHAPTER 5 – MANAGING INPUT AND OUTPUT OPERATIONS
CHAPTER 6 – DECISION MAKING AND BRANCHING
CHAPTER 7 – DECISION MAKING AND LOOPING

Unit II
Designing structured programs, functions, basics, parameter passing, storage classes- extern, auto,
register, static, scope rules, block structure, user-defined functions, standard library functions, recursive
functions, header files, C preprocessor, C program examples.

CHAPTER 7 – DECISION MAKING AND LOOPING


Go To
CHAPTER 10 – USER-DEFINED FUNCTIONS
xvi Road Map to the Syllabus
Unit III
Arrays- concepts, declaration, definition, accessing elements, storing elements, arrays and functions,
two-dimensional and multi-dimensional arrays, applications of arrays. pointers- concepts, initialization
of pointer variables, pointers and function arguments, address arithmetic, character pointers and
functions, pointers to pointers, pointers and multidimensional arrays, dynamic memory managements
functions, command line arguments, C program examples.

CHAPTER 8 – ARRAYS
Go To CHAPTER 9 – HANDLING OF CHARACTER
STRINGS
CHAPTER 11 – POINTERS
Unit IV
Derived types- structures- declaration, definition and initialization of structures, accessing structures,
nested structures, arrays of structures, structures and functions, pointers to structures, self-referential
structures, unions, typedef, bitfields, C program examples.

CHAPTER 12 – STRUCTURES AND UNIONS


Go To CHAPTER 15 – DYNAMIC MEMORY ALLOCATION
AND LINKED LISTS
Unit V
Input and output – concept of a file, text files and binary files, streams, standard I/o, formatted I/o, file
I/o operations, error handling, C program examples.

Go To CHAPTER 13 – FILE MANAGEMENT IN C


Unit VI
Searching – linear and binary search methods, sorting – bubble sort, selection sort, insertion sort, quick
sort, merge sort.

CHAPTER 17 – SORTING AND SEARCHING


Go To
TECHNIQUES

Unit VII
Introduction to data structures, singly linked lists, doubly linked lists, circular list, representing stacks
and queues in C using arrays and linked lists, infix to post fix conversion, postfix expression evaluation.
CHAPTER 14 – DATA STRUCTURES
Go To CHAPTER 15 – DYNAMIC MEMORY ALLOCATION
AND LINKED LISTS
Unit VIII
Trees- binary trees, terminology, representation, traversals, graphs—terminology, representation, graph
traversals (dfs and bfs)

Go To CHAPTER 16 – BINARY TREES AND GRAPHS


The C99 Standard

Computer languages are not static; they evolve, reacting to changes in methodologies, applications gen-
erally accepted practices, and hardware. C is no exception. In the case of C, two evolutionary paths were
set in motion. The first is the continuing development of the C language. The second is C++, for which
C provided the starting point. While most of the focus of the past several years has been on C++, the
refinement of C has continued unabated.
For example, reacting to the internationalization of the computing environment, the original C89
standard was amended in 1995 to include various wide-character and multibyte functions. Once the
1995 amendment was complete, work began on updating the language, in general. The end result is, of
course, C99. In the course of creating the 1999 standard, each element of the C language was thoroughly
reexamined, usage patterns were analyzed, and future demands were anticipated. As expected, C's rela-
tionship to C++ provided a backdrop for the entire process. The resulting C99 standard is a testimonial
to the strengths of the original. Very few of the key elements of C were altered. For the most part, the
changes consist of a small number of carefully selected additions to the language and the inclusion of
several new library functions. Thus C is still C!
Here we will examine those features added by C99, and the few differences between C99 and C89.

C99

Perhaps the greatest cause for concern that accompanies the release of a new language standard is the
issue of compatibility with its predecessor. Does the new specification render old programs obsolete?
Have important constructs been altered? Do I have to change the way that I write code? The answers to
these types of questions often determine the degree to which the new standard is accepted and, in the
longer term, the viability of the language itself. Fortunately, the creation of C99 was a controlled, even-
handed process that reflects the fact that several experienced pilots were at the controls. Put simply: If
you liked C the way it was, you will like the version of C defined by C99. What many programmers
think of as the world's most elegant programming language, still is! In this chapter we will examine the
changes and additions made to C by the 1999 standard. Many of these changes were mentioned in
passing in Part One. Here they are examined in closer detail. Keep in mind, however, that as of this
writing, there are no widely used compilers that support many of C99’s new features. Thus, you may
need to wait a while before you can ‘test drive’ such exciting new constructs as variable-length arrays,
restricted pointers, and the long long data type.
xviii The C99 Standard
C89 vs. C99: AN OVERVIEW

There are three general categories of changes between C89 and C99:
· Features added to C89
· Features removed from C89
· Features that have been changed or enhanced
Many of the differences between C89 and C99 are quite small, and clarify nuances of the C language.
This book will concentrate on the larger changes that affect the way programs are written.

Features Added

Perhaps the most important features added by C99 are the new keywords:
· inline
· restrict
_Bool
_Complex
_Imaginary
Other major additions include
· Variable-length arrays
· Support for complex arithmetic
· The long long int data type
· The //comment
· The ability to intersperse code and data
· Additions to the preprocessor
· Variable declarations inside the for statement
· Compound literals
· Flexible array structure members
· Designated initializers
· Changes to the printf( ) and scanf( ) family of functions
· The _ _func_ _ predefined identifier
· New libraries and headers
Most of the features added by C99 are innovations created by the standardization committee, of
which many were based on language extensions offered by a variety of C implementations. In a few
cases, however, features were borrowed from C++. The inline keyword and // style comments are exam-
ples. It is important to understand that C99 does not add C++-style classes, inheritance, or member
functions. The consensus of the committee was to keep C as C.

Features Removed

The single most important feature removed by C99 is the ‘'implicit int’ rule. In C89, in many cases when
no explicit type specifier is present, the type int is assumed. This is not allowed by C99. Also removed
is implicit function declaration. In C89, if a function was not declared before it is used, an implicit
declaration is assumed. This is not supported by C99. Both of these changes may require existing code
to be rewritten if compatibility with C99 is desired.
The C99 Standard xix
Features Changed

C99 incorporates several changes to existing features. For the most part, these changes expand features
or clarify their meaning. In a few cases, the changes restrict or narrow the applicability of a feature.
Many such changes are small, but a few are quite important, including:
· Increased translation limits
· Extended integer types
· Expanded integer type promotion rules
· Tightening of the return statement
As it affects existing programs, the change to return has the most significant effect because it might
require that code be rewritten slightly.
Throughout the remainder of this chapter, we will examine the major differences between C89 and
C99.

RESTRICT-QUALIFIED POINTERS

One of the most important innovations in C99 is the restrict type qualifier. This qualifier applies only to
pointers. A pointer qualified by restrict is initially the only means by which the object it points to can be
accessed. Access to the object by another pointer can occur only if the second pointer is based on the
first. Thus, access to the object is restricted to expressions based on the restrict-qualified pointer.
Pointers qualified by restrict are primarily used as function parameters, or to point to memory allocated
via malloc( ). The restrict qualifier does not change the semantics of a program. By qualifying a
pointer with restrict, the compiler is better able to optimize certain types of routines by making the
assumption that the restrict-qualified pointer is the sole means of access to the object. For example, if
a function specifies two restrict-qualified pointer parameters, the compiler can assume that the pointers
point to different (that is, non-overlapping) objects. For example, consider what has become the classic
example of restrict: the memcpy( ) function.
In C89, it is prototyped as shown here:
void *memcpy(void *str1, const void *str2, size_t size);
The description for memcpy( ) states that if the objects pointed to by str1 and str2 overlap, the
behaviour is undefined. Thus, memcpy( ) is guaranteed to work for only non-overlapping objects. In
C99, restrict can be used to explicitly state in memcpy( )’s prototype what C89 must explain with
words.
Here is the C99 prototype for memcpy( ):
void *memcpy
(void * restrict str1, const void * restrict str2, size_t size);
By qualifying str1 and str2 with restrict, the prototype explicitly asserts that they point to non-overlap-
ping objects. Because of the potential benefits that result from using restrict, C99 has added it to the
prototypes for many of the library functions originally defined by C89.

Inline

C99 adds the keyword inline, which applies to functions. By preceding a function declaration with
inline, you are telling the compiler to optimize calls to the function. Typically, this means that the
xx The C99 Standard
function’s code will be expanded in line, rather than called. However, inline is only a request to the
compiler, and can be ignored. Specifically, C99 states that using inline ‘suggests that calls to the func-
tion be as fast as possible.’ The inline specifier is also supported by C++, and the C99 syntax for inline
is compatible with C++.
To create an in-line function, precede its definition with the inline keyword. For example, in the
following program, calls to the function max( ) are optimized:
#include <stdio.h>
inline int max(int a, int b)
{
return a > b ? a : b;
}
int main(void)
{
int x=5, y=10;
printf("Max of %d and %d is: %d\n", x, y, max(x, y));
return 0;
}
For a typical implementation of inline, the preceding program is equivalent to this one:
#include <stdio.h>
int main(void)
{
int x=5, y=10;
printf("Max of %d and %d is: %d\n", x, y, (x>y ? x : y));
return 0;
}
The reason that inline functions are important is that they help you create more efficient code while
maintaining a structured, function-based approach. As you probably know, each time a function is
called, a significant amount of overhead is generated by the calling and return mechanism. Typically,
arguments are pushed onto the stack and various registers are saved when a function is called, and then
restored when the function returns. The trouble is that these instructions take time.
However, when a function is expanded in line, none of those operations occur. Although expanding
function calls in line can produce faster run times, it can also result in larger code size because of
duplicated code. For this reason, it is best to inline only very small functions. Further, it is also a good
idea to inline only those functions that will have significant impact on the performance of your program.
Remember: Although inline typically causes a function’s code to be expanded in line, the com-
piler can ignore this request or use some other means to optimize calls to the function.

NEW BUILT-IN DATA TYPES

C99 adds several new built-in data types. Each is examined here.
The C99 Standard xxi
_Bool

C99 adds the _Bool data type, which is capable of storing the values 1 and 0 (true and false). _Bool is
an integer type. As many readers know, C++ defines the keyword bool, which is different from _Bool.
Thus, C99 and C++ are incompatible on this point. Also, C++ defines the built-in Boolean constants
true and false, but C99 does not. However, C99 adds the header <stdbool.h>, which defines the macros
bool, true, and false. Thus, code that is compatible with C/C++ can be easily created.
The reason that _Bool rather than bool is specified as a keyword is that many existing C programs
have already defined their own custom versions of bool. By defining the Boolean type as _Bool, C99
avoids breaking this preexisting code. However, for new programs, it is best to include <stdbool.h> and
then use the bool macro.

_Complex and _Imaginary

C99 adds support for complex arithmetic, which includes the keywords _Complex and _Imaginary,
additional headers, and several new library functions. However, no implementation is required to imple-
ment imaginary types, and freestanding implementations (those without operating systems) do not have
to support complex types. Complex arithmetic was added to C99 to provide better support for numerical
programming.
The following complex types are defined:
· float _Complex
· float _Imaginary
· double _Complex
· double _Imaginary
· long double _Complex
· long double _Imaginary
The reason that _Complex and _Imaginary, rather than complex and imaginary, are specified as
keywords, is that many existing C programs have already defined their own custom complex data types
using the names complex and imaginary. By defining the keywords _Complex and _Imaginary, C99
avoids breaking this preexisting code.
The header <complex.h> defines (among other things) the macros complex and imaginary, which
expand to Complex and _Imaginary. Thus, for new programs, it is best to include <complex.h> and
then use the complex and imaginary macros.

The long long Integer Types

C99 adds the long long int and unsigned long long int data types. A long long int has a range of at
least–(263–1) to 263–1. An unsigned long long int has a minimal range of 0 to 264–1. The long long
types allow 64-bit integers to be supported as a built-in type.

Array Enhancements

C99 has added two important features to arrays: variable length and the ability to include type qualifiers
in their declarations.
xxii The C99 Standard
Variable-Length Arrays

In C89, array dimensions must be declared using integer constant expressions, and the size of an array is
fixed at compile time. C99 changes this for certain circumstances. In C99, you can declare an array
whose dimensions are specified by any valid integer expression, including those whose value is known
only at run time. This is called a variable-length array (VLA). However, only local arrays (that is,
those with block scope or prototype scope) can be of variable length.
Here is an example of a variable-length array:
void f(int dim1, int dim2)
{
int matrix[dim1] [dim2]; /* a variable-length, 2-D array */
/* . . . */
}
Here, the size of matrix is determined by the values passed to f( ) in dim1 and dim2. Thus, each call to
f( ) can result in matrix being created with different dimensions.
It is important to understand that variable-length arrays do not change their dimensions during their
lifetime. (That is, they are not dynamic arrays.) Rather, a variable-length array can be created with a
different size each time its declaration is encountered.
You can specify a variable-length array of an unspecified size by using * as the size.
The inclusion of variable-length arrays causes a small change in the sizeof operator. In general, sizeof is
a compile-time operator. That is, it is normally translated into an integer constant whose value is equal
to the size of the type or object when a program is compiled. However, when it is applied to a variable-
length array, sizeof is evaluated at run time. This change is necessary because the size of a variable-
length array cannot be known until run time.
One of the major reasons for the addition of variable-length arrays to C99 is to support numeric
processing. Of course, it is a feature that has widespread applicability. But remember, variable-length
arrays are not supported by C89 (or by C++).

Use of Type Qualifiers in an Array Declaration

In C99 you can use the keyword static inside the brackets of an array declaration when that declaration
is for a function parameter. It tells the compiler that the array pointed to by the parameter will always
contain at least the specified number of elements. Here is an example:
int f(char str [static 80])
{
// here, str is always a pointer to an 80-element array
// . . .
}
In this example, str is guaranteed to point to the start of an array of chars that contains at least 80
elements.
You can also use the keywords restrict, volatile, and const inside the brackets, but only for function
parameters. Using restrict specifies that the pointer is the sole initial means of access to the object.
The C99 Standard xxiii
Using const states that the same array is always pointed to (that is, the pointer always points to the same
object). The use of volatile is allowed, but meaningless.

Single-Line Comments

C99 adds the single-line comment to C. This type of comment begins with // and runs to the end of
the line.
For example:
// This is a comment
int i; // this is another comment
Single-line comments are also supported by C++. They are convenient when only brief, single-line
remarks are needed. Many programmers use C’s traditional multiline comments for longer descriptions,
reserving single-line comments for “play-by-play” explanations.
Interspersed Code and Declarations In C89, within a block, all declarations must precede the first
code statement. This rule does not apply for C99.
For example:
#include <stdio.h>
int main(void)
{
int i;
i = 10;
int j; // wrong for C89; OK for C99 and C++
j = i;
printf(“%d %d”, i, j);
return 0;
}
Here, the statement i = 10; comes between the declaration of i and the declaration of j. This is not
allowed by C89. It is allowed by C99 (and by C++). The ability to intersperse declarations and code is
widely used in C++.
Adding this feature to C makes it easier to write code that will be used in both environments.

PREPROCESSOR CHANGES

C99 makes a number of small changes to the preprocessor.

Variable Argument Lists

Perhaps the most important change to the preprocessor is the ability to create macros that take a variable
number of arguments. This is indicated by an ellipsis (. . .) in the definition of the macro. The built-in
preprocessing identifier _ _VA_ARGS_ _ determines where the arguments will be substituted.
xxiv The C99 Standard
For example, given this definition
#define MyMax(. . .) max(__VA_ARGS__)
this statement
MyMax(a, b);
is transformed into
max(a, b);

There can be other arguments prior to the variable ones. For example, given
#define compare(compfunc, . . .) compfunc(__VA_ARGS__)
this statement
compare(strcmp, “one”, “two”);
is transformed into
strcmp(“one”, “two”);
As the example shows, _ _VA_ARGS_ _ is replaced by all of the remaining arguments.

The _Pragma Operator

C99 includes another way to specify a pragma in a program: the _Pragma operator. It has the following
general form:
_Pragma (“directive”)
Here, directive is the pragma being invoked. The addition of the _Pragma operator allows pragmas to
participate in macro replacement.

Built-in Pragmas

C99 defines the following built-in pragmas:


Pragma Meaning
STDC FP_CONTRACT ON/OFF/DEFAULT When on, floating-point expressions are
treated as indivisible units that are handled
by hardware-based methods. The default
state is implementation defined.
STDC FENV_ACCESS ON/OFF/DEFAULT Tells the compiler that the floating-point en-
vironment might be accessed. The default
state is implementation defined.
STDC CX_LIMITED_RANGE ON/OFF/DEFAULT When on, tells the compiler that certain for-
mulas involving complex values are safe. The
default state is off.
You should refer to your compiler’s documentation for details concerning these pragmas.
The C99 Standard xxv
Additional Built-in Macros

C99 adds the following macros to those already supported by C89:

_ _STDC_HOSTED_ _ 1 if an operating system is present.

_ _STDC_VERSION_ _ 199901L or greater. Represents version of C.

_ _STDC_IEC_559_ _ 1 if IEC 60559 floating-point arithmetic is supported.

_ _STDC_IEC_599_COMPLEX_ _ 1 if IEC 60559 complex arithmetic is supported.

_ _STDC_ISO_10646_ _ A value of the form yyyymmL that states the year and
month of the ISO/IEC 10646 specification supported by the
compiler.

Declaring Variables within a for Loop

C99 enhances the for loop by allowing one or more variables to be declared within the initialization
portion of the loop. A variable declared in this way has its scope limited to the block of code controlled
by that statement. That is, a variable declared within a for loop will be local to that loop. This feature
has been included in C because often the variable that controls a for loop is needed only by that loop. By
localizing this variable to the loop, unwanted side effects can be avoided.
Here is an example that declares a variable within the initialization portion of a for loop:
#include <stdio.h>
int main(void)
{
// declare i within for
for(int i=0; i < 10; i++)
printf(“%d ”, i);
return 0;
}
Here, i is declared within the for loop, rather than prior to it.
As mentioned, a variable declared within a for is local to that loop. Consider the following program.
Notice that the variable i is declared twice: at the start of main( ) and inside the for loop.
#include <stdio.h>
int main(void)
{
int i = -99;
// declare i within for
for(int i=0; i < 10; i++)
printf(“%d”, i);
printf(“\n”);
xxvi The C99 Standard
printf(“Value of i is: %d”, i); // displays-99
return 0;
}
This program displays the following:
0123456789
Value of i is: -99
As the output shows, once the for loop ends, the scope of the i declared within that loop ends. Thus, the
final printf( ) statement displays –99, the value of the i declared at the start of main( ).
The ability to declare a loop-control variable inside the for has been available in C++ for quite some
time, and is widely used. It is expected that most C programmers will do the same.

Compound Literals

C99 allows you to define compound literals, which are array, structure, or union expressions designat-
ing objects of the given type. A compound literal is created by specifying a parenthesized type name,
which is then followed by an initialization list, which must be enclosed between curly braces. When the
type name is an array, its size must not be specified. The object created is unnamed.
Here is an example of a compound literal:
double *fp = (double[]) {1.0, 2.0, 3.0};
This creates a pointer to double, called fp, which points to the first of a three-element array of double
values.
A compound literal created at file scope exists throughout the lifetime of the program. A compound
literal created within a block is a local object that is destroyed when the block is left.

Flexible Array Structure Members

C99 allows you to specify an unsized array as the last member of a structure. (The structure must have
at least one other member prior to the flexible array member.) This is referred to as a flexible array
member. It allows a structure to contain an array of variable size. The size of such a structure returned
by sizeof does not include memory for the flexible array.
Typically, memory to hold a structure containing a flexible array member is allocated dynamically,
using malloc( ). Extra memory must be allocated beyond the size of the structure to accommodate the
desired size of the flexible array.
For example, given
struct mystruct {
int a;
int b;
float fa[]; // flexible array
};
the following statement allocates room for a 10-element array:
The C99 Standard xxvii
struct mystruct *p;
p = (struct mystruct *) malloc(sizeof(struct mystruct) + 10 *
sizeof(float));
Since sizeof(struct mystruct) yields a value that does not include any memory for fa, room for the 10-
element array of floats is added by the expression
10 * sizeof(float)
when malloc( ) is called.

Designated Initializers

A new feature of C99 that will be especially helpful to those programmers working with sparse arrays is
designated initializers. Designators take two forms: one for arrays and one for structures and unions.
For arrays, the following form is used,
[index] = val
where index specifies the element being initialized to the value val. For example:
int a[10] = { [0] = 100, [3] = 200 };
Here, only elements 0 and 3 are initialized.
For structure or union members, the form used is:
. member-name
Using a designator with a structure allows an easy means of initializing only selected members of a
structure.
For example:
struct mystruct {
int a;
int b;
int c;
} ob = { .c = 30, .a = 10 };
Here, b is uninitialized.
Using designators also allows you to initialize a structure without knowing the order of its members.
This is useful for predefined structures, such as div_t, or for structures defined by some third party.

Additions to the printf( ) and scanf( ) Family of Functions

C99 adds to the printf( ) and scanf( ) family of functions the ability to handle the long long int and
unsigned long long int data types. The format modifier for long long is ll.
For example, the following fragment shows how to output a long long int and an unsigned long long
int:
long long int val;
unsigned long long int u_val;
printf(“%lld %llu”, val, val2);
xxviii The C99 Standard
The II can be applied to the d, i, o, u, and x format specifiers for both printf( ) and scanf( ).
C99 adds the hh modifier, which is used to specify a char argument when using the d, i, o, u, or x
format specifiers. Both the ll and hh specifiers can also be applied to the n specifier.
The format specifiers a and A, which were added to printf( ), cause a floating-point value to be
output in a hexadecimal format. The format of the value is
[-]0xh.hhhhp+d
When A is used, the x and the p are uppercase. The format specifiers a and A were also added to
scanf( ), and read a floating-point value.
In a call to printf( ), C99 allows the 1 modifier to be added to the %f specifier (as in %lf), but it has
no effect. In C89, %lf is undefined for printf( ).

NEW LIBRARIES IN C99

C99 adds several new libraries and headers. They are shown here:
Header Purpose
<complex.h> Supports complex arithmetic.
<fenv.h> Gives access to the floating-point status flags and other
aspects of the floating-point environment.
<inttypes.h> Defines a standard, portable set of integer type names.
Also supports functions that handle greatest-width inte-
gers.
<iso646.h> Added in 1995 by Amendment 1. Defines macros that
correspond to various operators, such as && and ^.
<stdbool.h> Supports Boolean data types. Defines the macros bool,
true, and false, which help with C++ compatibility.
<stdint.h> Defines a standard, portable set of integer type names.
This header is included by <inttypes.h>.
<tgmath.h> Defines type-generic floating-point macros.
<wchar.h> Added in 1995 by Amendment 1. Supports multibyte and
widecharacter functions.
<wctype.h> Added in 1995 by Amendment 1. Supports multibyte and
widecharacter classification functions.

The _ _func_ _ Predefined Identifier

C99 defines _ _func_ _, which specifies the name (as a string literal) of the function in which
_ _func_ _ occurs.
For example:
void StrUpper(char *str)
The C99 Standard xxix
{
static int i = 0;
i++;
printf(“%s has been called %d time(s).\n”, __func__, i);
while(*str) {
*str = toupper(*str);
str++;
}
}
When called the first time, StrUpper( ) will display this output:
StrUpper has been called 1 time(s).

INCREASED TRANSLATION LIMITS

The term ‘translation limits’ refers to the minimum number of various elements that a C compiler must
be able to handle. These include such things as the length of identifiers, levels of nesting, number of case
statements, and number of members allowed in a structure or union. C99 has increased several of these
limits beyond the already generous ones specified by C89.
Here are some examples:
Limit C89 C99
Nesting levels of blocks 15 127
Nesting levels of conditional inclusion 8 63
Significant characters in an internal identifier 31 63
Significant characters in an external identifier 6 31
Members of a structure or union 127 1023
Arguments in a function call 31 127

Implicit int No Longer Supported

Several years ago, C++ dropped the implicit int rule, and with the advent of C99, C follows suit. In C89,
the implicit int rule states that in the absence of an explicit type specifier, the type int is assumed. The
most common use of the implicit int rule was in the return type of functions. In the past, C programmers
often omitted the int when declaring functions that returned an int value.
For example, in the early days of C, main( ) was often written like this:
main ()
{
/* . . . */
}
xxx The C99 Standard
In this approach, the return type was simply allowed to default to int. In C99 (and in C++) this default no
longer occurs, and the int must be explicitly specified, as it is for all of the programs in
this book.
Here is another example. In the past a function such as
int isEven(int val)
{
return !(val%2);
}
would often have been written like this:
/* use integer default */
isEven (int val)
{
return !(val%2);
}
In the first instance, the return type of int is explicitly specified. In the second, it is assumed by default.
The implicit int rule does not apply only to function return values (although that was its most
common use).
For example, for C89 and earlier, the isEven( ) function could also be written like this:
isEven(const val)
{
return ! (val%2);
}
Here, the parameter val also defaults to int—in this case, const int. Again, this default to int is not
supported by C99.
Note Technically, a C99-compatible compiler can accept code containing implied ints after re-
porting a warning error. This allows old code to be compiled. However, there is no requirement
that a C99-compatible compiler accept such code.

Implicit Function Declarations Have Been Removed

In C89, if a function is called without a prior explicit declaration, then an implicit declaration of that
function is created. This implicit declaration has the following form:
extern int name( );
Implicit function declarations are no longer supported by C99.
Note Technically, a C99-compatible compiler can accept code containing implied function dec-
larations after reporting a warning error. This allows old code to be compiled. However, there is
no requirement that a C99-compatible compiler accept such code.
The C99 Standard xxxi
Restrictions on return

In C89, a function that has a non-void return type (that is, a function that supposedly returns a value)
could use a return statement that did not include a value. Although this creates undefined behaviour, it
was not technically illegal. In C99, a non-void function must use a return statement that returns a
value. That is, in C99, if a function is specified as returning a value, any return statement within it must
have a value associated with it. Thus, the following function is technically valid for C89, but invalid for
C99:
int f(void)
{
/* . . . */
return ; // in C99, this statement must return a value
}

Extended Integer Types

C99 defines several extended integer types in <stdint.h>. Extended types include exact-width, mini-
mum-width, maximum-width, and fastest integer types.
Here is a sampling:

Extended Type Meaning

int16_t An integer consisting of exactly 16 bits


int_least16_t An integer consisting of at least 16 bits
int_fast32_t Fastest integer type that has at least 32 bits
intmax_t Largest integer type
uintmax_t Largest unsigned integer type
The extended types make it easier for you to write portable code.
For loop changes In a for-loop, the first expression may be a declaration, with a scope encompassing
only the loop.
for (decl; pred; inc)
stmt;
is equivalent to:
{
decl;
for (; pred; inc)
stmt;
}
Type specifiers or data types Type specifiers: new combinations added for:
· _Bool
· float _Complex, double _Complex, long double _Complex
· signed and unsigned long long int.
xxxii The C99 Standard
New type long long (signed and unsigned), at least 64 bits wide.
Note: It seems that these type specifiers may occur in any order, e.g, _Complex double long
or signed long int long would be legal.
The implementation of the complex types is defined by the standard to use cartesian coordinates (real
and imaginary part), i.e. forbids an implementation using polar coordinates (distance from [0,0] and an
angle). Furthermore, the same paragraph also specifies that a complex type has the same alignment
requirements as an array of two elements of the corresponding floating types, the first must be the real
part and the second the imaginary part.
Objects of the new boolean type _Bool may have one of the two values zero or one.

Format Modifiers for Printf( ) Added by C99

C99 adds several format modifiers to printf( ): hh, ll, j, z, and t. The hh modifier can be applied to d, i,
o, u, x, X, or n. It specifies that the corresponding argument is a signed or unsigned char value or, in
the case of n, a pointer to a signed char variable. The ll modifier also can be applied to d, i, o, u, x, X,
or n. It specifies that the corresponding argument is a signed or unsigned long long int value or, in the
case of n, a pointer to a long long int. C99 also allows the l to be applied to the floating-point specifiers
a, A, e, E, f, F, g, and G, but it has no effect. The j format modifier, which applies to d, i, o, u, x, X, or
n, specifies that the matching argument is of type intmax_t or uintmax_t. These types are declared in
<stdint.h> and specify greatest-width integers. The z format modifier, which applies to d, i, o, u, x, X,
or n, specifies that the matching argument is of type size_t. This type is declared in <stddef.h> and
specifies the result of sizeof.
The t format modifier, which applies to d, i, o, u, x, X, or n, specifies that the matching argument is of
type ptrdiff_t. This type is declared in <stddef.h> and specifies the difference between two pointers.

Sample code

#include <stdio.h>
int main(void)
{
/* This prints ''this is a test" left justified
in 20 character field.
*/
printf(“%-20s”, “this is a test”);
/* This prints a float with 3 decimal places in a 10
character field. The output will be " 12.235".
*/
printf(“%10.3f”, 12.234657);
return 0;
}

Changes to the Integer Promotion Rules

C99 enhances the integer promotion rules. In C89, a value of type char, short int , or an int bit-field can
be used in place of an int or unsigned int in an expression. If the promoted value can be held in an int,
the promotion is made to int; otherwise, the original value is promoted to unsigned int.
The C99 Standard xxxiii
In C99, each of the integer types is assigned a rank. For example, the rank of long long int is greater
than int, which is greater than char, and so on. In an expression, any integer type that has a rank less
than int or unsigned int can be used in place of an int or unsigned int.

THE PRINTF( ) FORMAT SPECIFIERS

Code Format
%a Hexadecimal output in the form 0xh.hhhhp+d (C99 only).
%A Hexadecimal output in the form 0Xh.hhhhP+d (C99 only).
%c Character.
%d Signed decimal integers.
%i Signed decimal integers.
%e Scientific notation (lowercase e).
%E Scientific notation (uppercase E).
%f Decimal floating point.
%F Decimal floating point (C99 only; produces uppercase INF, INFINITY,
or NAN when applied to infinity or a value that is not a number. The %f
specifier produces lowercase equivalents.)
%g Uses %e or %f, whichever is shorter.
%G Uses %E or %F, whichever is shorter.
%o Unsigned octal.
%s String of characters.
%u Unsigned decimal integers.
%x Unsigned hexadecimal (lowercase letters).
%X Unsigned hexadecimal (uppercase letters).
%p Displays a pointer.
%n The associated argument must be a pointer to an integer. This specifier
causes the number of characters written (up to the point at which the
%n is encountered) to be stored in that integer.
%% Prints a percent sign.

RESTRICT-QUALIFIED POINTERS

The C99 standard has added a new type qualifier that applies only to pointers: restrict. A pointer
qualified by restrict is initially the only means by which the object it points to is accessed. Access to the
object by another pointer can occur only if the second pointer is based on the first. Thus, access to the
object is restricted to expressions based on the restrict-qualified pointer. Pointers qualified by restrict
are primarily used as function parameters or to point to memory allocated via malloc( ). By qualifying
a pointer with restrict, the compiler is better able to optimize certain types of routines. For example, if
a function specifies two restrict-qualified pointer parameters, then the compiler can assume that the
pointers point to different (that is, non-overlapping) objects. The restrict qualifier does not change the
semantics of a program.
xxxiv The C99 Standard

1. /* Write a program to test the given string is palindrome or not. implement the program
by using _Bool datatype */
#include<stdio.h>
#include<string.h>
enum _Bool{false,true}; // _Bool DataType which is capable of
storing the vales 0 and 1
enum _Bool IsPalindrome(char string[]) // _Bool datatype
{
int left,right,len=strlen(string);
enum _Bool matched=true; // _Bool datatype
if(len==0)
return 0;
left=0;
right=len-1;
/* Compare the first and last letter,second & second last & so
on */
while(left<right&&matched)
{
if(string[left]!=string[right])
matched=false;
else
{
left++;
right--;
}
}
return matched;
}

int main()
{
char string[40];
clrscr();
printf("****Program to test if the given string is a
palindrome****\n");
printf("Enter a string:");
scanf("%s",string);
if(IsPalindrome(string))
printf("The given string %s is a palindrome\n",string);
else
printf("The given string %s is not a palindrome\n",string);
getch();
return 0;
}
The C99 Standard xxxv

2. /* In C89, within a block, all declarations must precede the first code statement. This rule
does not apply for C99 */
#include<stdio.h>
int main(void)
{
int i;
i=10;
int j; //wrong for c89; ok for c99
j=i;
clrscr();
printf("%d %d",i,j);
return 0;
getch();
}
3. /* Write a program to print the signed and unsigned numbers by using C99 standards*/
#include<stdio.h>
int main(void)
{
int i= -99;
{
for(int i=0; i<10; i++) //declare i within for
printf("%d",i);
printf("\n");
}
printf("Value of i is: %d",i); //display-99
return 0;
}
4. /* Write a program to open the file by using C99 standards */
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *fp;
if((fp=fopen("test","wb"))==NULL);
{
printf("cannot open file.\n");
exit(1);
fprintf(fp,"this is a test %d %f", 10,20.01); // fprintf
fclose(fp);
return 0;
}
}
xxxvi The C99 Standard

5. /* Write a C program that uses functions to perform the following operations by using
C99 standards(_Complex, _Imaginary):
(i) Reading a complex number
(ii) Writing a complex number
(iii) Addition of two complex numbers
(iv) Multiplication of two complex numbers
(Note: represent complex number using a structure.) */
#include<stdio.h>
#include<math.h>
#include<complex.h>

void _Complex(int opern);

struct comp
{
double realpart;
double _Imaginary;
};

void main()
{
int opern;
clrscr();
printf("\n\n \t\t\t***** MAIN MENU *****");
printf("\n\n Select your option: \n1 : ADD\n2 : MULTIPLY\n0 :
EXIT \n\n\t\t Enter your Option [ ]\b\b");

scanf("%d",&opern);

switch(opern)
{
case 0:
exit(0);
case 1:
case 2:
_Complex(opern);
default:
main();
}

void _Complex(int opern)


The C99 Standard xxxvii

{
struct comp w1, w2, w;
printf("\n Enter two Complex Numbers (x+iy):\n Real Part of
First Number:");
scanf("%lf",&w1.realpart);
printf("\n Imaginary Part of First Number:");
scanf("%lf",&w1._Imaginary);
printf("\n Real Part of Second Number:");
scanf("%lf",&w2.realpart);
printf("\n Imaginary Part of Second Number:");
scanf("%lf",&w2._Imaginary);
switch(opern)
{
/*addition of complex number*/
case 1:
w.realpart = w1.realpart+w2.realpart;
w._Imaginary = w1._Imaginary+w2._Imaginary;
break;

/*multiplication of complex number*/


case 2:
w.realpart=(w1.realpart*w2.realpart)-
(w1._Imaginary*w2._Imaginary);

w._Imaginary=(w1.realpart*w2._Imaginary)+(w1._Imaginary*w2.realpart);
break;
}

if (w._Imaginary>0)
printf("\n Answer = %lf+%lfi",w.realpart,w._Imaginary);
else
printf("\n Answer = %lf%lfi",w.realpart,w._Imaginary);
getch();
main();
}
6. /* Write a program to find the maximum number by using C99 standards(inline keyword)
*/
#include <stdio.h>
inline int max(int a, int b) // inline keyword
{
return a > b ? a : b;
xxxviii The C99 Standard

}
int main(void)
{
int x=5, y=10;
printf("Max of %d and %d is: %d\n", x,y,max(x,y));

return 0;
}
7. /* Write a C program to generate Pascal's Triangle by using C99 standards */
#include<stdio.h>
#include<conio.h>

void main()
{
int bin,q,r;
clrscr();
bin=1;
q=0;

printf("Rows you want to input:");


scanf("%d",&r);

printf("\nPascal's Triangle:\n");

while(q<r)
{
for(int p=40-3*q;p>0;--p) // declare p with in for
printf(" ");
for(int x=0;x<=q;++x) // declare x with in for
{
if((x==0)||(q==0))
bin=1;
else
bin=(bin*(q-x+1))/x;
printf("%6d",bin);
}

printf("\n");
++q;
}
getch();
}
The C99 Standard xxxix

8. /* Write a C program to generate all the prime numbers between 1 and n, where n is a
value supplied by the user by using C99 standards.(long long int,declare variables with in
for loop) */
#include <stdio.h>

void main()
{
long long int no,check; // long long int
clrscr();
printf("<-----------------------PRIME NO. SERIES--------------
---------->");
printf("\n\n\n\t\t\tINPUT THE VALUE OF N: ");
scanf("%d",&no);
printf("\n\nTHE PRIME NO. SERIES B/W 1 TO %lld : \n\n",no);

for(int counter = 1; counter <= no; counter++) // declare


counter with in for
{
check = 0;
//THIS LOOP WILL CHECK A NO TO BE PRIME NO. OR NOT.

for(int counter1 = counter-1; counter1 > 1 ; counter1--)


if(counter%counter1 == 0)
{
check++; // INCREMENT CHECK IF NO. IS NOT A PRIME NO.
break;
}
if(check == 0)
printf("%d\t",counter);
}
getch();
}
9. /* Write a program to print text and numbers by using C99 standards */
#include<stdio.h>
int main(void)
{
printf("%-20s","this is a test"); // left justified
printf("%10.3f",12.234657);
return 0;
}
xl The C99 Standard

10. /* Write a program for addition of matrices by using the restrict keyword */
void fadd(double a[static restrict 10],
const double b[static restrict 10]) // restrict keyword, restricrts a and b
{
int i;
for(i=0; i<10; i++)
{
if(a[i] < 0.0)
return;
a[i] += b[i];
}
return;
}
11. /* Write a C program to find the roots of a quadratic equation by using format modifiers
in C99. */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,root1,root2;
clrscr();
printf("\n Enter values of a,b,c for finding roots of a qua-
dratic eq:\n");
scanf("%f%f%f",&a,&b,&c);
/*checking condition*/
if(b*b>4*a*c)
{
root1=-b+sqrt(b*b-4*a*c)/2*a;
root2=-b-sqrt(b*b-4*a*c)/2*a;
printf("\n*****ROOTS ARE*****\n");
printf("\nroot1=%1.3f\nroot2=%1.2f",root1,root2); //format
modifiers for printf()
}
else
printf("\n Imaginary Roots.");
getch();
}
The C99 Standard xli

12. /* Write a C program to find the sum of individual digits of a positive integer by using long
long int in C99 standards*/
#include<stdio.h>
#include<conio.h>
void main()
{
long long int num, k=1, sum=0; // long long int
clrscr();
printf("Enter the number whose digits are to be added:");
scanf("%lld",&num);
while(num!=0)
{
k=num%10;
sum=sum+k;
k=num/10;
num=k;
}
printf("Sum of the digits:%lld",sum);
getch();
}
UNIT I
Chapter
1
Algorithms

1.1 INTRODUCTION

There is a tremendous similarity between the human actions and the way a computer performs various
functions. Nicholas Wirth—the inventor of a computer language—‘Pascal’ used to say “A program is
equal to algorithm + data”. In the next few chapters, we will explore the meaning of these terms; first
learning about and clearly analyzing human actions and then showing how computers also act similarly,
thereby demystifying the complexity that surrounds computers.
We perform hundreds of activities during a day. An activity could be anything from brushing teeth to
making tea and from going to work to having dinner. There are two basic ways to describe in detail, any
of these activities:
1. By describing the process step-by-step—called as algorithm.
2. By representing the various steps in the form of a diagram—called as flow chart.

1.1.1 Algorithm/pseudocode

The term algorithm is very popular in the computer literature. An algorithm is also called pseudocode.
At first, it might sound very complex. However, it is very simple to understand. In fact, we all perform
hundreds of algorithms in our daily life without even realizing it!
Algorithm is the step-by-step method of performing any task. When we break up a big task into
smaller steps, what we actually do is to create an algorithm. In other words, we perform hundreds of
algorithms. Brushing teeth, making tea, getting ready for school or office, are all different algorithms.
For example, when making a cup of tea, we follow the algorithm as shown in Fig. 1.1 (with a few
variations, of course!).
An interesting observation: Many steps can be further sub-divided into still smaller sub-steps. For
example, we can write an algorithm for Step 1 (Boil water) by writing detailed steps for boiling water.
However, it is up to an individual as to how detailed steps one should describe. Each step can be called
as an instruction. Also, we can notice that steps 4 and 5 can be executed in parallel, i.e. we can boil
milk while we wait. In actual life, there is a tremendous amount of parallelism in many of our actions.
We normally hear, see and feel simultaneously to comprehend a situation. Within this also, when we see
1.4 C Programming and Data Structures
a picture, for example, actually we see millions of spots of the picture to generate an image on our retina
while we compare all dots in parallel with already stored millions of images to identify an object instan-
taneously! Therefore, parallel computing was developed to speed up things and ultimately try to
imitate human actions in artificial intelligence. We need not discuss these in detail in later chapters,
but continue with serial algorithms for now.
Begin
1. Boil water.
2. Put tea powder in the kettle.
3. Pour boiled water in the kettle.
4. Wait for three minutes.
5. Boil milk.
6. Put boiled milk in a cup.
7. Add sugar to the cup.
8. Empty the kettle in the cup.
9. Stir the cup with a spoon.
End

Fig. 1.1 Algorithm for making tea

1.1.2 Flow Chart

There is another way to write the steps involved in any process. This is by making use of various
symbols. The symbols form a diagram that represents the steps in a pictorial fashion similar to an
algorithm. This is also very easy to understand. Such a diagram is called flow chart. In its simplest
form, a flow chart consists of a series of rectangles connected to each other by arrows. The rectangles
represent the various steps and the arrows designate the flow. A flow chart for our tea-making example
could be drawn as in Fig. 1.2.

Fig. 1.2 Flow chart for making tea


Algorithms 1.5
As can be seen, these are very primary concepts that we learn since childhood. We learn to make tea
by observing someone making tea: just like any other activity. Thus, the algorithm for making tea was
recorded in our brain long back somewhere deep—in our memory. There is another part of our memory
which stores the details of our current activity or thoughts. Whenever we want to make tea, somehow
this algorithm is brought back from our deep memory into the current memory (i.e. it is ‘remembered’)
and then it is actually executed. This concept of storing something in memory, retrieving it back in the
current memory (i.e. ‘remembering’ it) whenever needed and actually performing a task is very primi-
tive, yet extremely important, as we shall see, due to its similarity with computers.

1.2 THREE BASIC OPERATIONS

The tea-making algorithm and flow chart discussed earlier were quite simple. One step followed another
in a sequential fashion. However, things are not so simple in real life! There are so many ifs and buts.
For example, consider the following statements:
∑ If it is 9 am, I must go to the office.
∑ If it is raining, take your umbrella with you.
∑ Read each line and say it loudly until the end of this page.
How do we take care of such things in an algorithm and a flow chart? And how many different kinds
of situations we must cater to? This section attempts to answer these questions.
In general, the steps in an algorithm can be divided in three basic categories as listed below:
∑ Sequence—A series of steps that we perform one after the other
∑ Selection—Making a choice from multiple available options
∑ Iteration—Performing repetitive tasks
These three basic categories of activities combined in different ways can form the basis for describ-
ing any algorithm. It might sound surprising initially. But it is true. Think of any situation in our daily
life and try to fit it in one of the three categories: it works!
Let us now look at each of the categories in more detail.

1.2.1 Sequence

A sequence is a series of steps that we follow in any algorithm without any break, i.e. unconditionally.
The algorithm for making tea described in Fig. 1.1 belongs to this category. Figure 1.3 describes another
algorithm in this category for ‘boiling water’. What this means is that we have exploded further the step
or instruction 1 in the algorithm for making tea given in Fig. 1.1. We can explode all such steps in Fig.
1.1 in the following way.
Begin
1. Take a utensil.
2. Take the utensil to the water tap.
3. Open the tap.
4. Fill the utensil with water.
5. Close the tap.
6. Put the utensil on the gas or in the oven.
7. Start the gas or the oven.
8. Wait until the water boils.
9. Switch off the gas or the oven.
End

Fig. 1.3 Algorithm for boiling water


1.6 C Programming and Data Structures

We will not draw the flow chart for boiling water. It should be clear by now that it is a matter of
writing all of the above 9 steps in rectangles one after the other; each connected to its successor by an
arrow.

1.2.2 Selection

We will quickly realize that only ‘sequence’ is not good enough to express an algorithm. Quite a few of
our actions depend on certain events. Thus, there is a need to be able to make a choice from many
available options. Therefore, there is a process of selection. A selection statement generally takes the
form as shown in Fig. 1.4.
1. If
2. Then
3. End-if

Fig. 1.4 Selection

We take so many decisions, small and big, in our daily life without even realizing it. For example, if
it is hot, we switch on the fan. We can depict this selection process as shown in Fig. 1.5.
1. If it is hot
2. Then switch on the fan
3. End-if

Fig. 1.5 Example of a selection

Note that End-if is an additional step that indicates the end of the selection process. A question may
be asked: is End-if really necessary? Let us illustrate this by the following selection process that does
not have an End-if. Refer to Fig. 1.6.
1. If the guest wants tea
2. Then make tea
3. Offer biscuits

Fig. 1.6 Importance of End-if

What do we do if the guest does not want tea? Do we offer him biscuits? It is not clear from the
selection process described above. It can be argued and proved either way. That is, we are not sure
whether the Offer biscuits portion is a part of our If condition or not. A miserly person would always say
that he considers Offer biscuits as a part of the condition, and hence would only offer biscuits to some-
one who wants tea! Hence, it is always better to end a selection process with an End-if to avoid any
confusion at least for our algorithms. Different computer programming languages have different con-
ventions.
The position and placement of End-if instructions can change the meaning of the entire algorithm as
shown in Fig. 1.7 (a) and 1.7 (b). Let us study the algorithm shown in Fig. 1.7 (a). If the guest wants tea,
the algorithm will execute step 2 after step 1 (i.e. make tea), then fall through step 3 and then step 4 (i.e.
offer biscuits). Thus, if the guest wants tea, he gets the biscuits, too! Now, let us trace the algorithm if
the guest does not want tea. In this case, the algorithm will follow step 3 after step 1 (i.e. skip the tea)
and then fall through step 4 (i.e. offer biscuits). Thus, biscuits will be offered regardless of tea. If we
study algorithm shown in Fig. 1.7 (b), we will notice that biscuits are offered only with tea. If the guest
Algorithms 1.7
does not want tea, the algorithm will follow step 1 and directly step 4. The semicolon at the end of step
2 indicates that tea and biscuits are offered together. You will notice that the positioning of End-if
(at step 3 or 4) has made all the difference! The Figs 1.8 (a) and 1.8 (b) show the corresponding flow
charts.
Begin Begin
1. If the guest wants tea 1. If the guest wants tea
2. Then make tea 2. Then make tea;
3. End-if 3. offer biscuits
4. Offer biscuits 4. End-if
End End

Fig. 1.7(a) Offer biscuits to all guests Fig. 1.7(b) Offer biscuits only to guests who
want tea

Guest Yes Guest Yes


wants Make wants Make
tea? tea tea? tea

No No Offer biscuits

Offer biscuits

Fig. 1.8(a) Fig. 1.8(b)

In both of these cases (a and b), we have not specified the action if the guest wants coffee. Let us
modify our algorithm and also the flow chart to accommodate that possibility. Note that we are offering
coffee as an alternative to tea. We will be generous enough to offer biscuits in either case. Since we want
to offer the biscuits irrespective of the acceptance/rejection of tea/coffee offer, we should consider only
the first algorithm for modification, viz. Fig. 1.7(a). The modified algorithm and its corresponding flow
chart are shown in Figs 1.9 and 1.10 respectively.
Begin
1. If the guest wants tea
2. Then make tea
3. End-if
4. If the guest wants coffee
5. Then make coffee
6. End-if
7. Offer biscuits
End

Fig. 1.9 Algorithm for offering tea/coffee and biscuits


1.8 C Programming and Data Structures

Guest Yes
wants Make
tea? tea

No

Yes
Guest Make
wants Coffee
Coffee?

No

Offer biscuits

Fig. 1.10 Flow chart for offering tea/coffee and biscuits

Note that we offer biscuits regardless of the acceptance of the tea/coffee offer. That is exactly what
we had wanted. Consider the following algorithm as shown in Fig. 1.11(a). Figure 1.11(b) shows the
corresponding flow chart.

Begin
1. If the guest wants tea
2. Then make tea
3. Offer biscuits
Offer
4. End-if
Guest Yes
5. If the guest wants coffee
coffee Make
wants
6. Then make coffee
coffee tea
tea?
7. Offer biscuits
Offer
8. End-if
End Offer biscuits
No
(a) Algorithm

Guest Yes
wants Make
coffee? coffee

No Offer biscuits

(b) Flow chart

Fig. 1.11 Offering biscuits only if guest wants tea /coffee


Algorithms 1.9
Can it achieve the same objective as the algorithm shown in Fig. 1.9? A close examination will reveal
that it is not the same. For instance, if the guest rejects both tea and coffee, the algorithm shown in
Fig. 1.9 offers the guest biscuits regardless. However, the algorithm shown in Fig. 1.11(a) does not offer
anything! How easily things that seem similar can mislead us, as they actually are different. These are
the things that one needs to be careful of while writing an algorithm. Otherwise, it leads to the program-
ming errors called as bugs, which programmers refer to, all the time.
We will notice some problem in the algorithm and flow charts depicted in Figs 1.9–1.11. After a
guest chooses to have tea, the algorithm still asks if the guest wants coffee. Unless a guest wants both
simultaneously, this is completely wasteful. We can avoid this by introducing a goto instruction. Using
this, we can rewrite the algorithm of Fig. 1.9 as shown in Figs 1.12 (a) and 1.12 (b).

Begin
1. If the guest wants tea
2. Then make tea
3. Goto LAST
4. End-if
5. If the guest wants coffee
coffee Guest Yes
wants Make
6. Then make coffeecoffee tea
7. End-if tea?
8. LAST:
LAST: OfOffer
fer Biscuits
End

(a) Algorithm No

Guest Yes
Make
wants
coffee
coffee?

No

Offer biscuits

(b) Flow chart

Fig. 1.12 Improved algorithm to avoid unnecessary step

In this algorithm, LAST is called label for an instruction. Offer biscuits (step 8). This allows the goto
instruction to branch to a specific instruction. However, the goto makes a program difficult to understand and
therefore, modify. So, generally, gotos are avoided. If you avoid such a goto in a program, you can read the
program starting at the top and ending at the bottom without branching up or down. This is called as goto-less
or top-down or structured programming method. Such programs are easy to understand and therefore, easy
to maintain. We will see how the same algorithm can be written in a structured fashion later.

1.2.2.1 The compound conditions

It is very easy to group different conditions into one. We generally use words like and and/or or to join
sentences. In the same way, we can combine two or more conditions into a single compound condition.
For example, take a look at the algorithm shown in Fig. 1.13.
1.10 C Programming and Data Structures

Fig. 1.13 Compound conditions with and

In this algorithm, you are doing two things together, viz. taking breakfast and going to work. However,
you perform these only if all the three conditions are met, viz. it has to be a weekday, it has to be at least 7
am and you have to be feeling good. If any of these is not valid, you will not perform both of these actions.
For instance, if it is 7 am, and you are feeling ok, but if it is a weekend, you will not perform both the
actions. But then if you take the algorithm very seriously in real life, you will notice a bug. You will not go
to work on a weekend all right, but you will also have to skip your breakfast! So, be careful!
Similarly, the algorithm in Fig. 1.14 illustrates the use of or word to join two or more conditions.
(Note that we are now assuming implicit Begin and End statements for our algorithms.)

Fig. 1.14 Compound conditions with or

In this case, even if any of the conditions is met, you have breakfast and go to work. For instance, if
your boss is angry, then even if it is a holiday and there is actually no pending work, you will still
perform these two actions. Only if all the three conditions are not met, you skip having breakfast and
going to work.

1.2.2.2 The nested conditions

Sometimes, things are not very easy to express. With a variety of situations to worry about, it becomes
really complicated. For example, if something depends on still something else to happen (or otherwise),
there will be an if within another if. We will call it a nested condition. Let us look at an example.

Fig. 1.15 Nested conditions

You will notice that there is an If at the beginning (step 1) and corresponding End-if at the bottom
(step 9), which denotes the end of that If condition. Within this, you will notice another If and End-if pair
Algorithms 1.11
written in the same columns (steps 4 and 8). The Else provides an alternative path of execution. Let us
trace the algorithm if you are ok. In this case, the algorithm executes step 2, skips steps 3 through 8 and
goes directly to step 9. If you are not ok but you do not have fever, the algorithm goes through steps 1, 3,
4, 6, 7, 8 and 9. You will not go to work and you will just relax, but you will not consult a doctor even
if you have stomach pain. This is a bug!
If you are not ok and if you have fever, you will go through steps 1, 3, 4, 5, 8 and 9. In this case, you
will not go to work, you will not consult the doctor, but you will not relax. So, there is another bug. Try
removing it!
Let us rewrite the first algorithm of Fig. 1.6 using nested conditions. This will make the benefit of
else clearer.

Fig. 1.16 The ‘tea-coffee’ algorithm using nested conditions

As can be seen, if the guest accepts the offer for tea, we would simply make tea and offer biscuits
without bothering if he wants coffee (unless the guest wants both!). This does not happen in Fig. 1.6. It
might not make a big difference if we have just one or two conditions to check. However, as the number
of conditions increases, it is desired that the algorithm be as compact and efficient as possible.
As a further illustration, let us write an algorithm to find the largest of any three given numbers. It is
very easy to write an algorithm to find the larger of two numbers. Assuming that the two numbers are
a and b, we simply need to compare the two. However, when there are three numbers, things are a bit
complicated. The algorithm is as shown in Fig. 1.17.
1. If a > b
2. Then If a > c
3. Then choose a
4. Else choose c
5. End-if
6. Else If b > c
7. Then choose b
8. Else choose c
9. End-if
10. End-if

Fig. 1.17 Selecting the largest of three numbers

To ascertain that the algorithm indeed works as expected, we might assign values as 15, 2 and 21 to
a, b and c respectively. When we imagine these numbers in place of a, b and c in the above algorithm and
check if the algorithm works correctly, it is called as a pencil run of our algorithm. It is also termed as
a walkthrough of an algorithm. It is always a good practice to do a walkthrough of an algorithm with a
variety of values. That is, we should take a, b and c such that once a is the greatest of them all (e.g. a =
7, b = 2 and c = 1), then b (e.g. a = 13, b = 20, c = 10) and then c (e.g. a = 18, b = 24, c = 49). This will
make sure that our algorithm gives the correct result in each case. When we are doing a walkthrough of
our algorithm in this fashion, we are actually checking if it works fine.
Another random document with
no related content on Scribd:
Jos edesvastuunne onkin suuri, ei teidän myöskään pidä unohtaa,
että se etu, se onni, mikä teille on suotu, panna isänmaanne
vapaustaistelu alkuun, on suuri ja kaunis. Täyttäköön tämä ajatus
teidät kiitollisuudella Jumalaa kohtaan, ilomielisellä urhoollisuudella
ja uhrautuvaisuudella.

Kaikkia näitä seikkoja tulee teidän ajatella nyt rintamalle


lähtiessänne. Kun te kerran olette saapuneet vihollisen eteen, ei
enää voi peräytyä, ei epäröidä. Te olette silloin sotalakien alaisia.
Luonnollisesti ei tule kysymykseenkään, että saksalaisten joukossa
käytettäisiin sellaisia raakalaistapoja, kuin venäläisten kesken, jotka
ampuvat omia sotamiehiä, jos he peräytyvät. Mutta Saksassa
asetetaan sotaoikeuden eteen ja rangaistaan ankarasti se, joka ei
sodassa tottele, joka nukkuu vahdissa ollessaan ja saattaa lepäävät
toverinsa vaaraan tai joka osottaa pelkuruutta taistelussa. Toiseksi
nämä lait tuomitsevat sen, joka rikkoo inhimillisyyden lait
turvattomia kohtaan ja joka ei noudata sotilaskunnian sääntöjä.
Urhoollista sotilasta sitävastoin odottavat ylennykset, kunniamerkit ja
toverien arvonanto ja hänen nimensä tulee säilymään jälkimaailmalle
ja Suomen historiassa. Varmaankin oli tällainen teidän päätöksenne,
kun te vaikeuksista ja tulevaisuutenne epävarmuudesta huolimatta
lähditte pitkälle matkallenne Suomesta tänne asti liittyäksenne
vapaaehtoisesti joukkoomme.

Pitäkää päämääränne vakaasti silmienne edessä. Pysykää


päätöksessänne, täyttäkää isänmaallinen velvollisuutenne,
käyttäytykää urhoollisesti ja toverillisesti saksalaisia joukkoja
kohtaan, jotka teidän rinnallanne taistelevat venäläistä vastaan.
Muistakaa kiitollisuudella Hänen Majesteettiansa Saksan keisaria,
joka on sallinut saksalaisten upseerien ja aliupseerien valmistaa
teidät kelpo sotilaiksi. Älkää koskaan unohtako, mikä on taistelunne
päämaali: Suomen vapaus!

Baier

Majuri ja pataljoonan komentaja.

MATKA RINTAMALLE.

Ennenkuin saksalainen pataljoona lähtee rintamalle, varustetaan se


niin hyvin että siitä todella ei puutu nappiakaan. Viikon varrella
ennen lähtöä on joka päivä tarkastuksia. Kaikki, mikä on huonoa,
kulunutta, hyljätään ja uudet, lujat vaatteet, aseet ja varustukset
annetaan kelvottomien sijaan. Pidetään takkitarkastus, lakki-,
housu-, saapas-, kivääri-, pistintarkastus, miltei joka vaate- ja
varuskappale tarkastetaan erikseen. Lopuksi on yleinen
pukutarkastus sekä vihdoin viimeinen tarkastus siitä, sopivatko kaikki
hihnat, laukut, napit y.m. paikoilleen. Kun nappiakaan ei puutu, on
komppania valmis lähtemään.

Toukokuun 20 päivän vaiheella suomalainen jääkäripataljoona


valmistui rintamakuntoon. Oli vuoden ihanin aika käsillä. Leiri oli
kauneimmillaan lehtipuitten peitossa. Kaikki kentät viheriöitsivät.
Tuntuipa miltei raskaalta erota tuosta sirosta kylästä, noista tutuiksi
tulleista harjoituskentistä, joilla monta vilua ja päivänpaahdettakin oli
kestetty ja ankarasti harjoiteltu.

Kuitenkin sieltä lähti mielellään. Olihan tuleva retki kuin ensi askel
synnyinmaata kohti. Nyt alkoi tosi toiminta, taistelu Suomesta.
Kukaan ei aavistanut, että se oli tuleva niin pitkäksi ja raskaaksi.
Olimme vakuutetut kevään suuren yleishyökkäyksen alkamisesta
idässä heti kun onneton Verdun-jakso oli loppuun suoritettu, ja
edellisen syksyn loistava eteneminen Puolassa ja Kuurinmaalla sekä
Hindenburg-nimi tuntuivat takaavan nopean ratkaisun
sotanäyttämöllä.

Jokainen aavisti kuitenkin, että tuleva aika oli raskas taistelujen


aika, mutta se ajatus kasvatti rintoihin tarmon ja vakavan mielen.
Tämä mieliala tuli kauniisti esille illallisilla Kaiserhofissa, johon
etupäässä joukon akateemiset kansalaiset ottivat osaa. Laulut ja
puheet vaihtelivat molemmilla kielillä ja tuntui tosiaankin kerran kuin
henki olisi ollut yksi. Leirille saapunut vanha vapaaherra v. Bonsdorff
lausui puheessaan m.m.: — Koko Suomen tulevaisuus riippuu nyt
tästä pienestä joukosta. Ennen oli Suomella vähän ystäviä, nyt sillä
on ystävänä mahtavin kaikista kansoista, — Saksan kansa!

Harjoitusten yhä jatkuessa kului vielä viikon päivät lähtökäskyä


odotellessa. Kun joka pieninkin asia selitettiin oppitunnilla, oli
luonnollista, että pari, kolme kertaa esitelmöitiin rautatiematkasta ja
käyttäytymisestä sen kuluessa. Juuri ennen lähtöä saapui
kolmanteen komppaniaan uusi luutnantti, Lindner nimeltään ja
siviiliammatiltaan opettaja. Hänen puheensa olivat aito
saksalaismallisia, helppotajuisia, järjestelmällisiä ja perusteellisia.
Puhuipa hän mistä tahansa, aihe oli aina jaettu kolmeen osaan.

— Also — — erstens, zweitens und drittens! Mutta näiden kolmen


kohdan jälkeen seurasi aina vankka "aber" ja tämän otsakkeen alla
kaikki mahdolliset poikkeustapaukset. Hänen esitelmänsä
rautatiematkasta oli luonnollisesti myöskin jaettu kolmeen osaan: i)
junaan nousu, 2) käyttäytyminen vaunuissa matkalla ja 3) junasta
poistuminen. Kaikki muu, mikä ei mahtunut näiden otsakkeiden
puitteisiin, selvitettiin aber-sanan jälkeen. Kaikessa tapauksessa
noita esityksiä mieli virkeänä kuunteli niiden selvyyden vuoksi.

Toukokuun viimeisen päivän aamuna komppaniat kokoontuivat


viimeisen kerran kasarmien pihalle kaikki tamineet mukana. Nuo
pitkät, vihreät rivit olivat sotaisen näköiset ja ryhti hyvä. Upseerit
asettuivat paikoilleen. Kajahti komennus. Rivistö lähti liikkeelle. Porin
marssi raikuu torvista. Kasvot ovat vakavat kaikilla. Niissä kuvastuu
pidätetty tarmo ja koura puristaa lujasti kiväärin tukkia. Eräs
Lappajärven poika kuiskaa: "Ihan haluttaa itkeä!" — Suomalaiset
jääkärit astuivat ensi askeleensa kotimaata kohti. Marssi kävi kylän
läpi. Koko väestö oli liikkeellä, ovet, ikkunat auki, nenäliinat liehuivat.

Juna oli valtavan pitkä, onneksi kolmannen luokan vaunuja.


Jokaiseen osastoon pakattiin ryhmä kimpsuineen kampsuineen. Torvi
törähti, kaikki astuivat vaunuihin. Pitkä, kimeä vihellys. Juna liikkui,
maisemat häipyivät taakse, jäi punakattoinen Lockstedtin leiri. Sen
kuuluisa Wasserturm painui metsän peittoon.

Liikkeelle lähtiessämme kajahti raikas eläköönhuuto pitkin junaa.


Oli kaunis nähdä tuo laaksojen läpi kiemurteleva juna, jonka
akkunoiden kohdalla helotti häikäisevä rivi vihreitä pukuja, iloisia,
nauravia kasvoja. Eri ikkunoiden välillä kävi hilpeä leikinlasku,
vaunusta vaunuun kun lähetettiin sanoja ja komennuksia.

Hiljaa, tavarajunan vauhdilla, porhalsimme eteenpäin. Sotilasjunat


kulkevat yleensä hiljaa, milloin ei ole erikoista hätää. Usein ne
tekevät pitkiä kierroksiakin, että vakoojain olisi vaikea saada selville,
mihin kukin rykmentti kuljetetaan.
Pohjois-Saksan kaupungit kaartuvat ohitse. Lübeck'in asemalta
kajahti junan ohi kulkiessa Maamme-laulu. Kaupungin suomalaiset
olivat kokoontuneet asemalle lausuakseen viimeiset
onnentoivotuksensa Suomen jääkäreille.

Hammersteinissa pistivät erikoisesti silmiin laajat, miltei silmän


kantomatkan päähän ulottuvat vankileirit. Leiri lienee Saksan
suurimpia. Rautatien molemmin puolin avautuva tasanko on
ympäröity korkealla rautalanka-aituuksella. Asunnot ovat kaivetut
hietamaahan, vain katot ja ilmareijät kohoavat yli kentän. Ulkona
liikkuvien tuhansien vankien enemmistö oli venäläisiä. Näimme taas
nuo tutut harmaat sinellit ja nenässä tuntui ryssän haju. Musikat
olivat välinpitämättömän näköisiä. Jotkut heilauttivat kättään
itäänpäin viitaten kuin sanoakseen: "Menkää vain sinne miesten
syöjille sijoille, menkää menehtymään, me jäämme mieluummin
tänne."

Yhä eteenpäin yötäpäivää. Ainainen jyrinä ja katseleminen alkoi


väsyttää. Miehet makailivat telttakankaissaan, joita olivat ripustelleet
vaunun kattoon, toiset nukkuivat penkeillään. Virkeimmät soittelivat
huuliharppujaan tai savikukkojaan.

Königsberg — linnoitus, laaja kaupunki jylhine tiilikasarmeineen.


Ensimäinen näkemämme juna haavoittuneita saapui vastaan. Se oli
pitkä juna, mistä näkyi siteitä, verta ja tuntui formaliinin haju.

— Voi käydä niin että jonkun viikon kuluttua palaamme takaisin


tuolla junalla, kuului vakava ääni.

Muut vaikenivat: — Olkoon niinkin. Isänmaa on vaatinut!


Itä-Preussi, venäläiskauhun ja kasakkain hävityksen kärsinyt maa,
Hindenburgin ja Saksan armeijan loistavimpien voittojen maa,
Saksan vapautettu vilja-aitta! Sodan jälkiä alkaa näkyä. Siltojen
ympärillä on piikkilanka-aitaukset, aukeiden laidoissa näkyy
ampumahautalinjoja. Siellä täällä törröttää autio, puoleksi murtunut
tehtaan piippu korkeuteen kertoen sodan tihutöistä.

— Ja tuolla, tuolla, katsokaa!

Pienen metsäsaarekkeen reunassa on hautakummulla kaksi ristiä


ja niiden juurella kukkaseppeleen ympäröimänä saksalainen
sotilaskypärä. Täällä on taisteltu.

Miten tarkkaan ensi kertaa rintamalle matkaaja katseleekaan


sodan jälkiä, sen puolustus- ja hävitystöitä, taistelujen merkkejä!
Sanoin kuvaamattomia tunteita hänessä herättävät sotilashaudat.
Kaukanahan häntä itseään vartovat sotakentät, taistelut ja monet
kovat, raudankovat ihmiskohtalot.

Itä-Preussi, ihmeiden maa! Se on ollut oikea Saksan vilja-aitta,


nisun ja rukiin maa. Sanomalehdistä on kyllin tunnettu tuo ankara
onnettomuus, mikä sodan alussa kohtasi tätä kaunista rikasta
aluetta. Venäläisten kasakkaparvet kiitivät poltellen, ryöstellen ja
ennenkuulumattomia julmuuksia harjoitellen laajalti ympäri maata ja
peräytyessään vihollinen vei kaiken, mitä arvokasta ehti saada,
mukanaan Venäjälle.

Toisaalla seudut, aivan taistelupaikatkin, ovat kärsineet sangen


vähän, toisaalla taas hävitys on ollut ankara. Mutta mieli riemastuu
katsellessa sitä työtä ja virkeää toimintaa, mikä jälleen vallitsee
hävitystä kärsineillä alueilla. Siinä on jälleen todella esimerkillinen
kuva saksalaisesta "Bienenfleiss" uutteruudesta, kuten he itse
sanovat. Eräs aikakauslehti kertoo mieltäkiinnittäviä asioita tämän
alueen kuntoon panosta, saksalaisen työn ja tarmon tuloksista
seuraavaan tapaan:

"Heikoin on rakennus- ja parantelutoiminta pohjoisosissa Tilsitin ja


Memelin välillä, mutta seuduissa, missä rakennusainetta on kylliksi,
talot ovat pian nousseet tuhastaan. Asukkaille on uudelleen hankittu
eläimiä, karjaa kaikenlaista. Ensin on pystytetty tallit ja navetat ja
niihin laitettu ihmisille jonkinlaiseksi hätäasunnoksi huone tai pari.
Kun eläimet on saatu kunnon katon alle, rakennetaan ihmisasunnot
uudestaan hallintavirastojen tarkkojen määräysten mukaan. Itä-
Preussi on merkillisen nopeasti parantanut haavansa. 35 kaupunkia
ja 1900 maapitäjää joutui kärsimään sodan kauhuja ja hävitystä.
Muun muassa venäläiset veivät 872,000 nautaa, maasta joitten
avulla kenraali Rennenkampf aikoi uudistaa ja parantaa karjarodun
Itämeren maakunnissa. Joulukuun 1 p:nä v. 1914 oli tilastotietojen
mukaan Itä-Preussissa jälellä 903,137 nautaa, 183,955 lammasta ja
28,462 vuohta, jotavastoin 15 p:nä maaliskuuta v. 1916 vastaavat
luvut olivat 1,69,645, lehmää, 351,700 lammasta ja 43,791 vuohta.
Samaan tapaan on edistys käynyt maatalouden aloilla. V. 1914 ei
koko satoa voitu korjata, kaikkialla kun puuttui työvoimaa, vaunuja
ja hevosia, vaikkakin sotaväkeä tuotiin avuksi. Vuonna 1915
maanomistajat jo yleensä itse korjasivat sadon. Vuoden 1916 laajat,
viheriät viljaulapat ovat mitä kaunein todistus kansan työkunnosta!"

Tilsit. Tässä on siis tuo historiallinen paikka, missä vuonna 1807


Ranskan mahtava keisari Napoleon I ja Venäjän hallitsija Aleksanteri
I ratkaisivat Suomenkin kohtalon. Voimakkaalla persoonallisuudellaan
Napoleon hurmasi Venäjän nuoren ihanteellisen tsaarin, antoi tälle
tehtäväksi niskottelevan Ruotsin kurittamisen ja siitä toimesta
palkaksi Suomen. Tuossa kylmässä sopimuksessa ei kansan mieltä
eikä tahtoa kuultu.

— Mennään tekemään uudet ja paremmat sopimukset, kuuluu


jääkärijoukosta.

Kokonaisvaikutus Itä-Preussista on erittäin eloisa ja vilkas, aivan


toinen, minkä kouluissa tavallisesti saa maantieteen tunneilla.

Seuraavana aamuna heräämme — Kuurinmaalla. On pilvinen


päivä. Kummastellen katselemme ikkunasta uusia maisemia ja
huokaus tunkeutuu rinnasta: — Venäjän vallan raukat rajamaat! On
kuljettu rajan yli, kaikki on muuttunut. Laajat, silmänkantamattomat
metsät peittävät maan. Pellot ovat viljelemättä, talot mustat,
ränsistyneet. Kurjia autioita hökkeleitä siellä täällä.

Jokilaakso. Silta räjäytetty. Mustat palaneet jäännökset törröttävät


rannalla puoleksi vedessä. Piikkilangat repaleina, risuesteet
murskana.
Rantatöyräällä on juoksuhautoja. Jokilaaksossa on käyty laaja
taistelu.
Saksan sotavoimat ovat voittajina tunkeutuneet eteenpäin pyhään
Venäjään.

Asema livahtaa ohi. Sen rakennukset ovat raunioina, mustana


poro- ja soraläjänä. Radan varrella näkyy räjähtäneitten granaattien
kuoria ja sirpaleita. Kaidoilla kärryteillä harvoin näkyy laiha hevonen
ja venäläiset nelipyöräiset vankkurit, valjaissa tuo tuttu, korkea
vemmel. Rattaitten sisään kyyristyneenä istuu vanha vaimo. Hänen
kasvonsa ovat ryppyiset, pelokkaat. Kavalat silmät pälyvät kulkijan
harmaan villasaalin laskosten alta. Paljon kärsineen ihmisen kasvot,
ensimäinen Kuurinmaalla näkemämme asukas, — alkuasukas,
haluttaisi sanoa, häipyy näkyvistä. Nuo kasvot, tuo kurjuuden kuva
painuu kauaksi mieleen.

Nyt vasta meille selviää sodan koko traagillisuus — selviää laajan


luonnonrikkaan Kuurinmaan kohtalo. Iso-viha on käynyt
Kuurinmaalla. Kaikki hävitetty, tyhjennetty, asukkaat karkotetut
kylistä ja kaupungeista, kuljetetut Venäjän erämaihin kurjuuteen ja
kuolemaan. Pelloilla tuolla on vielä mustia pilkkuja — kasakkain
polttamien heinäsuovien jälkiä. Teiden varsilla on vieläkin rattaiden
jäännöksiä, rikkinäisiä pöytiä, saaveja — pakolaisjoukon jälkeensä
jättämää omaisuutta.

Kaameat kuvat täyttävät mielen. Tuossako on kuva isänmaamme


kohtalosta. Käykö senkin noin, ennenkuin vainolainen on
kotiseudultamme karkoitettu? Siinä on silmäimme edessä synkät
jäljet kuuluisasta venäläisten sodankäyntitavasta — Suvorovin
metoodista, jota venäläiset upseerit vieläkin rajamaissa käyttävät.
Venäläiset! He ovat hyviä hävittämään, vahinko vain, että he ovat
niin huonoja rakentamaan!

Mutta uusi polvi ja uudet ihmiset astuvat täälläkin entiskansan


hylkäämille pelloille ja rakennuksille. Tuolla saksalaiset sotilaat
niittävät heinää, perkaavat penkkejä. Hävitettyjen siltojen viereen
tehdään uusi, puinen. Asemarakennukset kuin kasvavat maasta.
Sähkölennätin, ja puhelinlankoja vedetään rautatielinjoja pitkin.
Kuurinmaa on mainio viljelysmaa, oikea tulevaisuuden leipämaa.
Saksan hallussa se pian antaa kaksinkertaisen sadon ja kerran
kymmenkertaisen.

Metsiä, hökkeleitä, mustia, valtavia metsiä ja olkikattoisia taloja.


Ratakiskot uppoavat yhtyen kaukaisuuteen. Puhelinlinjat ulisevat
tuulessa. Yhä vieraammilta kaikuvat paikkojen nimet. Kymmeniä,
satoja kilometrejä olemme kiitäneet ventovierasta maata. Tuntuu
siltä kuin matkaisimme kotimaasta ääretönten etäisyyksien taa.

Asematalon seinällä riippuu suuri valkea taulu: - Ope-ra-ti-ons-ge-


biet.

Mi-mitä? Sotatoiminta-alue!

Varhainen aamu. Aurinko heloittaa kirkkaasti itäiseltä


taivaanrannalta. Junan ikkunoista näkyy aamuvalossa välkkyvä
aukea kenttä. Talot ovat valoisat, entistä paremmin rakennetut,
tehtaita, korkeita savupiippuja, taloja — katuja — — — suuri komea
kaupunki, Kuurinmaan pääkaupunki Mitau leveän Aa-joen varrella.

Juna pysähtyy suuren, tiilisen asemarakennuksen eteen. — Kaikki


ulos vaunuista, ruokakupit mukaan! kajahtaa komento. Komppaniat
kokoontuvat avaraan ruokasaliin, missä koko pataljoona yht'aikaa
mahtuu aterioimaan. Asemalla on suunnaton liike. Kuorma-autot
jyrisevät, siellä on tykistöä suurta ja pientä ja tavaraa jos minkä
laatuista. Sotavangit ahkeroivat niitä lastattaessa. Tuossa eräs
innokas maanpuolustaja auttaa venäläistä suuren laatikon
vääntämisessä ja lopulta lykkää kiväärinsä vangin käteen tarttuen
itse työhön koko hartian väellä.

Olemme Riian rintaman suurimmassa etappikeskuksessa, noin


puolentoista penikulman päässä taistelulinjasta. Huolimatta siitä, että
venäläiset ovat tyhjentäneet kaupungin, siellä vallitsee nyt kuohuva
elämä. Junia saapuu ja lähtee. Sotilaita, vankeja, tavaroita, hevosia
on kaikkialla. Aa-joen sillat ovat korjatut, uusia varastohuoneita
rakennetaan. Kaupungin laidassa kohoaa korkea tähystystorni, missä
sotilastähystäjä tarkkaa ympäristöä.
Jääkäripataljoonan jälleen marssivalmiiksi järjestyessä sattuu
välikohtaus, joka huvittaa poikia. Eräs Iivana saapuu rivistön vierelle,
katsella töllistelee sitä hetken suu auki, pudistaa sitten päätään ja
huokaa: "Riga kaputt!"

Torvet törähtävät. Pataljoona marssii noin 6 kilometrin päässä


olevaan huvilakylään asettuen sen autioihin rakennuksiin toistaiseksi
lepäämään matkan rasituksista.

RINTAMANTAKAISIA LAITOKSIA.

Eteemme avautuvat laajat näköalat täynnä työtä ja toimintaa


rintamalinjan takana. Ei olekaan helppo työ varustaa armeija kaikilla
välttämättömillä tarpeilla, aseilla, ruualla y.m. Mitaun lähistöllä
liikkuva saa havainnollisen käsityksen siitä, miten paljon työtä
vaaditaan, jotta voitaisiin pitää armeija taistelukuntoisena. Erikoisia
ponnistuksia on vaatinut Kuurinmaan soisten maa-alueitten
liiketeiden kunnossapito. Kuurinmaan kylä- ja maantiet ovat sateilla
pohjattomat, pettävät. Ne on täytynyt kattaa rautalangalla toisiinsa
kytketyillä rungoilla kilometrejä pitkälti. Näiden päälle on jälleen
luotu maata ja siten saatu tie edes hevoskuormia kannattavaksi.
Teiden molemmin puolin on kaivettu valtaojia, toisaalla tienvieriä
pönkitetty ja paranneltu. Paljon työtä on vaatinut siltojen
rakentaminen aina pienistä ylikäytävistä valtaviin rautatiesiltoihin
saakka. Parhaat tiet ovat muutamat maan halki kulkevat valtatiet,
esim. kivillälaskettu Mitaun — Riian tie. Teiden rinnalla risteilevät
monet sodan aikana rakennetut pikkuradat. Ne johtavat
rautatieasemilta usein peninkulmien päässä oleville rintamalinjoille ja
suuresti helpottavat kaikkien tarpeitten kuljetusta armeijalle.

Rintaman takana vallitsee jättiläisliikenne. Siellä työskentelevät


kokonaiset armeijat sotilaita harmaissa työpuvuissaan.

Siellä on sementtitehtaita, tiiliruukkeja uunintekoa varten,


sahalaitoksia, missä välttämätön rakennusaines valmistetaan.
Lähinnä rintamaa on saniteettiasemia ja kenttäsairaaloita, missä
haavoittuneille annetaan ensi apu. Kylpylät ja täidentapposaunat
ovat erittäin tärkeitä ja välttämättömiä laitoksia sotaväen
terveydenhoidon edistäjinä ja taistelussa likaisuutta ja kaikenlaatuisia
siitä johtuvia pikkuvihollisia vastaan.

Suuret kenttäleipomot varustavat armeijakunnat leivällä ja


kenttämyymälöistä sotilaat saavat ostaa välttämättömiä pikku
tarvekalujaan.

Vihreitten niittyjen ja peltojen välillä kaikki talot ovat käytetyt


sotatarpeitten säilytykseen, mainittujen laitosten ja sotilasvirastojen
palvelukseen tai sotilasten majoitukseen.

Valtateillä vallitsee mahtava liike. Autokuormastot ja


kaikenlaatuiset ajopelit vyöryvät siellä edestakaisin
silmänkantomatkan pituisina jonoina. Joukko-osastot marssivat
töihinsä tai rintamaosilleen. Teiden päätepaikoissa on ladottuna
kokonaisia tavaravuoria säilykelaatikoita, okalankarullia, rautalankaa,
maataloustarpeita, pahvia, puutavaraa, rautatiekiskoja, säkkejä
tonnittain, minkä kaiken arvo on ääretön. Kuitenkin kaikki on mitä
parhaassa järjestyksessä ja tarveaineitten jaossa noudatetaan mitä
suurinta säästäväisyyttä.
Tulemme sitten kaupunkiin, etappikeskukseen. Jokaisen talon
seinää koristaa suuri kilpi siinä olevan viraston nimeä ilmoittaen.
Siellä on upseerikasinot ja sotilaskodit, ylijohdon,
paikalliskomendantuurin, sotaoikeuden, intendentuurin ja
muonituslaitoksen monet virastot ja varastot, sotasairaalat kutakin
erikoisalaa varten (silmiä, korvia, hampaita, eri tauteja,
haavoittuneita j.n.e.), toipumiskodit y.m. Vihdoin laajat vankileirit
sijaitsevat kaupungin laidassa. Vangitkin ovat ahkerassa työssä. He
purkavat rautatievaunuja, lastaavat kuormat, parantavat katuja,
teitä, rakentavat siltoja. Kaikki mahdolliset voimat on, käytetty
yhteisen päämäärän palvelukseen.

Ja valtavinta kaikessa on näennäisestä melusta, häärinästä ja


sekasotkusta huolimatta järjestys, minkä tuntee vasta tuon
moniosaisen koneiston toimiva jäsen, valtavaa on se rauhallisuus ja
varmuus, millä kaikki tämä jättiläistyö suoritetaan. Se vasta tekee
rintaman lujaksi, murtumattomaksi.

Kun ihmetellen huomauttaa vanhalle maanpuolustajalle tästä


rautaisesta järjestyksestä ja työn nopeudesta, tarmokkuudesta,
hymyilee hän leveästi, itsetietoisesti myhähtäen: — S'ist Krieg, ist
Krieg Kamerad!

HYLJÄTYSSÄ KYLÄSSÄ.

Asumme pienessä keltaiseksi maalatussa huvilassa; sen akkunat ovat


rikotut, ovet kiskotut paikoiltaan. Asukkaat on venäläisten
peräytyessä pakotettu seuraamaan mukana Venäjän sydänmaita
kohti.
Uteliaina pojat kulkevat ympäri tarkastellen kaikkea, mitä talon
asukkaat ovat jättäneet jälkeensä. Yksi tuo mukanaan vanhan
padan, toinen viikatteen. Löydetään vasara ja nauloja, millä
paikataan ikkunoita ja rakennetaan vuoteita. Taloista kuuluu kalske
ympäri kylän.

Sievissä pikku puutarhoissa omenapuut vielä kukkivat, sireenit


lemuavat. Keskeltä puutarhaa on maasta kaivettu vahva raudoitettu
arkku, asukasten kätkemät kalleudet paljastettu ja viety. Erään talon
puutarhassa on hävitetty satoja mehiläispesiä, raa'asti kaadettu
maahan suureen monisarkaiseen mansikkamaahan, joka nyt villiytyy
hoidon puutteessa.

Eräs joukkue kaivoa kaivaessaan joutui joukkohautaan.

Hävityksen jäljet irvistävät huoneissa joka puolelta. Oven pielessä


viruu lehdet hajallaan lätinkielinen raamattu. Lattia on täynnä
papereita, kirjoja, kortteja ja valokuvia. Katselen ajatuksissani
lätinkielistä lukukirjaa. Siinä on nuoren kirjakielen runoa ja proosaa,
kirjallisuutta, minkä säilymisestä ei enää ole paljonkaan takeita
tämän Kuurinmaan ison-vihan jälkeen.

Kammoen ajattelee vuosi sitten täällä tapahtunutta


murhenäytelmää. On näkevinään nuo kasakkain piiskoillaan
kodeistaan karkoittamat vaikeroivat pakolaislaumat matkalla
tietymättömään maanpakolaisuuteen. Kuormat ovat täynnä
asukasten kalleinta omaisuutta. Siellä astuvat uupuneina vanhukset
ja lapset, miehet ja naiset. Kaikkien kasvoilla kuvastuu kurjuus ja
epätoivo. Mitä sitten, kun hevoset uupuvat, kun ruoka loppuu?
Tavarat, kaikki vanhat isiltä perityt kalleudet täytyy työntää
tiensyrjään vihollisen saaliiksi. Matkaa jatkaa epätoivoinen
kerjäläinen, koditon maankulkuri.
Siten on suurin osa lätin kansaa ajettu kodistaan, konnuiltaan
häviämään Venäjän loppumattomaan lumimereen. Kuurinmaan
rajoilla vielä viimeiset sytyttelevät tuliansa katsoen kaihoten
menetettyyn paratiisiinsa, kunnes taas pelko panee peräytymään
hyökkäävän vihollisen tieltä saksalaisen tykistön säestäessä tätä
valtavaa murhenäytelmää.

On ääretön, sovittamaton rikos tuo suuren kansan murha, rikos,


joka huutaa kostoa pimeälle Venäjälle. On rikos 20:nnellä
vuosisadalla ajaa kokonainen kansa maanpakoon, varsinkaan kun
käskyn antajalla ei ole kykyä ruokkia eikä majoittaa onnettomia ja
vielä enemmän, kun tuo työ on turha. Saksalaisten etenemistä se
kaikki ei ole minuuttiakaan myöhästyttänyt.

Aina inhottavammalta tuntuu tuo raakalaistyö, tuo assyyrialaisten


ja babyloonialaisten sodankäyntitapa, kun tietää, että venäläiset ovat
toimittaneet sen vain rajamaillaan, vierasheimoisten kansain
keskuudessa. Venäjän sydän on sorrettujen, vierasten kansojen
ympäröimä. Vain se alue on taistelukenttänä, suojamuurina. Niiden
kansojen nuoret miehet ovat pakotetut taistelemaan venäläisten
riveissä. Säälimättä Venäjä uhraa nuo maat ja kansat oman kurjan
nahkansa pelastamiseksi — mutta uhraa turhaan. Kerran iskee
Saksan kostava miekka suoraan Venäjän sydämeen. Hindenburgin
luona ollut suomalaisen pataljoonan valiojoukko palaa ja he tuovat
mukanaan tämän suuren sotapäällikön toivomuksen: — Jumalan
avulla on teidän asianne onnistuva.
III

MITAUN YMPÄRISTÖISSÄ.

KÄYNTI VANHASSA MITAUSSA.

Leveältä Mitaun — Riian valtatieltä johtaa vasta valmiiksi tullut suuri


puusilta Aa-joen yli kaupunkiin, n.s. Pappritz-Brücke, komentavan
kenraalin mukaan nimitetty. Sen yli kuormastot jyrisevät yötä ja
päivää. Kaupungin laidassa on ihana puisto ja ravintola, mistä
viehättävä näköala aukeaa yli Aan rantojen ja kylien. Titelmünden
valkea linna välkkyy harjulla, laajan vihreän puiston keskellä. Toisella
rannalla kohoavat kymmenet tehtaanpiiput hyljättyinä, kolkkoina.
Työ on tauonnut. Vainon veripäivät ovat sen pyhätöistään
karkoittaneet. Aa-joki virtaa leikkien, levähtäen, katsellen säihkyvin
kristallisilmin kuin ihmetellen autiutta ympärillään.

Tulemme kaupunkiin. Kadut ovat siistit, asumukset pienet, köyhät,


paitsi keskikaupungilla, missä muhkeat kivijättiläiset jo kohoavat
uuden ajan enteinä. Nuo suuret talot ovat sotilasviranomaisten
hallussa. Pienten mökkien kellahtavien ikkunain läpi näkyy joskus
vanhan lättiläisvaimon arat ryppyiset kasvot.

Sotaleiri-Mitausta emme välitä. Ohjaamme matkan


syrjäkaupungille, tuonne, missä vain muistot elävät, todelliseen
Mitauhun, hyljättyyn, autioon, kuolleitten kaupunginosaan.

Siellä kapeat kadut jo kasvavat heinää, talot hohtavat


sammaltunein seinin ja hyräilevät satujaan ammoin olleista onnen
päivistä. Kuljemme kirkon ohi, venäläisen, kupoolikattoisen. Sen
jykevä rautaportti on auki, vaikkakin ympäristö on tyhjä. Auki ovat
kellotapulin luukutkin ja tuolla ylhäällä riippuu vielä yksinäinen pieni
kello liikkumattomana, hiljaisena. Vain iltatuulessa se ikävöiden
humajaa yli tuon tuskan ja kärsimysten kyllästämän maan, soi
rukouksiaan niitten puolesta, jotka kaukana, kodittomina harhailevat,
ikuinen koti-ikävä mielessään.

Haudoilla kirkon juurella kuohuu luonto kukkarikkauttaan. Tämän


kaupungin kuolleet ovat onnellisemmat kuin elävät nyt karkoitetut
asukkaat. Kuolleet ovat rauhanmajansa löytäneet ja keskiyön tullen
he voivat suvituulen hengähdysten mukana hiipiä kuulumattomin
askelin umpeenkasvaneita kukkapolkuja koteihinsa puutarhoihin ja
pikku taloihin. Ovet ovat kaikkialla auki. Villi ruoho peittää penkereet.
Kulkijalle, joka hartain mielin istahtaa hyljätyn asumuksen penkille,
nuo seinät, huonekalut, kertovat ja kuiskailevat yhtämittaa kuin
kukin koettaisi voittaa toisensa entiselämän kuvailussa.

Hyljätty asunto onkin todella suuri, syväsisältöinen taru, jota


yksinään on kuunneltava. Kuvat seinällä, isä, äiti, veljet, ja siskot,
tuossa he ovat ilmeikkäinä majan oikeat asukkaat, kaksi jopa ehkä
kolme ihmispolvea peräkkäin. Venäläiset puvut, mutta kasvot —
slaavilaiset, lättiläiset, vai ehkä baltilaiset? Vaikea sanoa! Tuossa on
tyttö, vaaleatukkainen, sinisilmäinen. Tuolla pitkä sorja poika
sysimustille, tulisine silmineen — sotilaspuvussa, lakki kallellaan
venäläiseen tapaan. Mitkä ovat heidän kohtalonsa olleet? Kuka voi
siihen vastata. Mielikuvitus yksin!

Nurkassa katsoo kainona huoneen hiljaisuutta Jumalan äidin


verhottu kuva. Kukaan ei ole sen pyhyyttä koskemalla loukannut.

Eräällä pöydällä on vielä nuottilehtiä, venäläistä ja saksalaista


musiikkia rinnan. Ei sota eikä vaino voi taiteen pyhitetylle alueelle
tunkeiltua raaistavana, epäpyhänä. Siellä on neron valta, aatteen
voima, taiteen jumalallinen lahja, joka lämmittää jokaista
ihmissydäntä, mihin kansallisuuteen kuulummekaan — köyhiä ja
rikkaita.

Kirkon tornissa kumahtaa kello, viisari vierähtää muistuttaen


arkimaailmaa. Satumaailma väistyy sen äänten tieltä.

Äänettöminä vaellamme jälleen takaisin majoituskyläämme


miettien noita outoja ihmiskohtaloita — Mitaun kymmenien
tuhansien koditonten asukasten kohtaloa ja sodan valtavaa
tragediaa.

MITAUN VALLOITUS.

Kuurinmaan hallitsevana väestönä on monessa suhteessa


mielenkiintoinen baltilais-germaaninen kansanaines. Nuo uljaat,
valkeat linnat ja hovit sirosti kalustettuine huoneineen, kirjastoineen,
villeine puistoineen, kaikkineen, ovat omiaan herättämään
harrastusta sitä väestöluokkaa kohtaan, joka tässä kaukaisessa,
harvaan asutussa ja vähän huomiota herättäneessä maankolkassa
on ollut sivistyselämän kannattajana. Baltilaisen ylimystön suhde
maan rahvaaseen on ollut herran suhde palvelijaan, ja luultavasti sen
omallatunnolla suureksi osaksi on Kuurinmaan lättiläisen
kansanaineksen kurja alkuperäisyys ja kehittymättömyys. Hovien
asukkaat ovat viettäneet päivänsä ruhtinaallisen komeasti,
epäilemättä olleet lahjakasta sivistynyttä väkeä, mutta heillä ei ole
ollut mitään harrastusta lättiläisen kansanaineksen henkiseen
kohottamiseen. Missä ikinä vieläkin hovin herra, rouva tai neiti liikkuu
avaroilla vainioillaan, siellä alustalaiset lankeavat polvilleen, ryömivät
"armon" luo suudellakseen hänen vaatteidensa liepeitä.

Jos tuo baltilaisylimystö siis tässä suhteessa kantaakin vanhoja


syntejä hartioillaan, on se kuitenkin mielenkiintoinen juuri
erikoisasemansa vuoksi. Vuosisatojen kuluessa se on säilyttänyt
germaanisuutensa ja omintakeisen kulttuurinsa, elänyt halki aikojen
läheisessä henkisessä yhteydessä siihen maahan, missä sen
veriheimolaiset asuivat, onpa vielä täällä Kuurinmaan metsäseutujen
hiljaisuudessa elänyt omintakeista, henkisistä harrastuksista rikasta
elämää. Ja lopuksi ei voi olla mielenkiinnolla seuraamatta niitä
sisäisiä taisteluja ja ristiriitoja, mitä maailmansodan valtavista,
yllättävistä tapahtumista koitui Kuurinmaan baltilaiselle väestölle.
[Muist. Kuurinmaan saksalaisetkin nimittävät itseään balteiksi, mitä
nimitystä kansatieteellisesti käytetään ahtaassa merkityksessä
liettualaisista ja lättiläisistä.] Kun Mitau koko pataljoonamme
rintamalla-olon aikana oli sen toiminnan lähtökohtana, keskipisteenä,
siellä kun asuivat pataljoonan komentajat ja esikunta, siellä kun oli
suomalaisten sairaala ja lepokoti, herättänee ehkä lukijoissakin
mielenkiintoa seuraava "Mitauische Zeitung"-lehden seiostus tämän
kaupungin joutumisesta saksalaisten haltuun elokuussa v. 1915.
"Kun suuri maailmansota puhkesi, joutuivat Kuurinmaan
saksalaisbaltilaiset asukkaat todella traagilliseen ristiriitaan —
sydämen ja velvollisuuden ristiriitaan. Sydämen äänen mukaan he
olivat, heidän täytyi olla, elleivät tahtoneet kieltää koko entisyyttään,
saksalaisten puolella. Velvollisuus taas vaati päinvastaista. Mutta
yksikään baltilainen ei horjunut edes silmänräpäystäkään. He kaikki
pakottivat, vaikkakin syvintä tuskaa tuntien, sydämensä
vaikenemaan ja tekivät velvollisuutensa valtiolle täydelleen ja kaikilla
aloilla, upseereina, sotilaina, virkamiehinä, alamaisina.

"Hallituksen, vaikkakaan se ei ollut heille suopea — baltilaiset ovat


jo ammoin oppineet, että Venäjän hallituksen hyväntahtoisuuteen
heidän ei kannata luottaa — vain yksinkertaisesti järkevän
hallituksen, joka olisi katsonut omaa etuaan, olisi pitänyt suopeasti
kohdella baltilaisia nähdessään, miten he suhtautuivat tuohon
vaikeaan ristiriitaan.

"Vaan mitäpä tapahtui?

"Alkoi saksalaisvaino, jota pahempaa tuskin saattoi ajatella. Se


alkoi siten, että kaikki saksalaisten yhdistysten koulut, sitten itse
yhdistyksetkin, suljettiin. Seurasi sitten kielto saksankielen käytöstä
julkisuudessa, mutta julkisuus taas oli kaikki, mikä oli oman kodin
seinien ulkopuolella. Tämän kiellon rikkojat tuomittiin suuriin
rahasakkoihin tai vankeusrangaistuksiin. Lapsiinkaan nähden ei tehty
poikkeusta ja nämä joutuivat yhä uudestaan rangaistuksen alaisiksi.

"Sitten ryhdyttiin tuohon vanhaan keinoon — karkoittamiseen


hallinnollista tietä.

"Ilman mitään oikeuden tuomiota täytyi lukemattomien


balttilaisten lähteä itään aina Siperian kaukaisimpiin seutuihin
saakka. Monet monituiset kytkettiin vankikomeroihin. Mitä
vaarattomimpia ihmisiä, raihnaisia vanhuksia, kunnianarvoisia rouvia
ja lapsiakin kohtasi tuo onnettomuus samoin kuin maan
huomatuimpia ja ansiokkaimpia miehiä. Mitä typerin ja kurjin
ilmianto riitti usein aikaansaamaan tuon ankaran kohtalon iskun.

"Suuri on niiden lukumäärä, jotka ovat kärsimysten tiellään


menehtyneet tai kuolleet Siperian vankikomeroissa. Vielä useammat
odottavat raskainta puutetta kärsien lopullisen vapautuksen hetkeä.

"Kaiken lisäksi tuli vihdoin ero kodista ja konnusta, vaimosta ja


lapsista, hävitys ja rosvoaminen. Maa piti tehtämän erämaaksi, sen
asukkailta riistettiin kaikki oikeudet ja he joutuivat täydelleen
ryöstönhaluisten, häikäilemättömien virkamiesten uhreiksi. Se
menettely katkaisi kaikki siteet, se vieroitti uskollisimmatkin
hallituksesta. Baltilaiset eivät rikkoneet välejään hallitukseen, hallitus
itse rikkoi välit ja sysäsi luotaan nuo ihmiset, jotka eivät koskaan
olleet antaneet aihetta muihin syytöksiin kuin siihen, että he olivat
syntyneet saksalaisista äideistä ja loukkaamatta
alamaisvelvollisuuksiaan tahtoivat olla saksalaisia kuten heidän esi-
isänsäkin olivat olleet. Se — heidän saksalaisuutensa oli heidän
rikoksensa, sillä sodan päämäärät eivät koskeneet ainoastaan
Saksaa, vaan koko saksalaisuutta, mikä oli hävitettävä, perin pohjin
kitkettävä maasta.

"Tällä kannalla olivat asiat Kuurinmaalla. Silloin astuivat saksalaiset


soturit voittoisa saksalainen miekka kourassaan maahan. Kahdella
sysäyksellä he valtasivat maan, ensin Libaun ympäristöineen, sitten
keskeytymättömällä, voitokkaalla hyökkäyksellä koko alueen
Väinäjokeen ja Kuurinmaan pohjoiskärkeen saakka. Vain pienet
alueet jäivät vielä venäläisten käsiin.
"Mitaun asukasten tila oli venäläisvallan viime päivinä
muodostunut kerrassaan sietämättömäksi. Jokainen yksityinen
henkilö tunsi turvallisuutensa uhatuksi ja uskalsi tuskin liikkua
kaduilla. Poliisi ja sotilaat ottivat kiinni nuoret miehet ja sulkivat
heidät taloihin, mistä heidät suoraan vietiin juoksu- ja
ampumahautoja rakentamaan.

"Heinäkuun 31 p:nä, eräänä lauantaina, alottivat venäläiset


viranomaiset kaupungin tyhjentämisen. Mitä erilaisimmilla ajopeleillä,
joiden kuormana oli kaikenlaista kirjavaa taloustavaraa, kiiruhtivat
asukkaat asemalle ja Rigan valtamaantielle. Se oli kansainvaellus.

"Muutamat virkamiehet, niiden joukossa kunnon miehen maineen


saanut poliisimestari, jäivät kaupunkiin vielä sunnuntaihin asti.
Hyvään venäläiseen tapaan löivät he linnanpuiston hotellin kellarit
auki ja viettivät jäähyväisorgiat, joissa työstetty viini virtasi. Olihan
kaikki mennyttä. Siksi nautittiin kuten epätoivoinen pelaaja ennen
konkurssia täysin siemauksin.

"Yöllä leimusivat yltympäri tulipalot ja tuontuostakin kuului valtavia


räjähdyksiä. Sillat, kruunun rakennukset, tehtaat ja useat kaupungin
yksityisasunnoistakin räjäytettiin mielettömästi ja sytytettiin tuleen.
Palokunta yritti sammuttaa tulta ja ehkäistä sen levenemistä, mutta
sotaväki esti työn.

"Siten kului aika sunnuntain puolipäivään asti. Aamupäivällä alkoi


pienehkö pogromi, sotilaat murtautuivat viini- ja
väkijuomavarastoihin, tyhjensivät niiden sisällön ja alkoivat sitten
aivan juopuneina ryöstää kaupunkia. Kaupungin roskaväki liittyi
ryöstäjiin.
"Yhtäkkiä silloin — noin kello 1 i.p. saivat räjähdykset toisen
luonteen. Kuului havina, vihellys, räiskäys! Tykit puhuivat rautaista
kieltään. Saksan panssaroitu nyrkki kolkutti Mitaun porteille.

"Aan toiselta puolen vastasivat venäläiset. Siellä täällä iskivät


shrapnellit teille ja taloihin. Asukkaat pakenivat lujien kivimuurien
suojaan odottaen tuskaisina ja jännittyneinä.

"Sitten k:lo 3 i.p. hälinää kaduilla. Muutamat venäläiset sotilaat


juoksivat käytävillä, iskivät kiväärintukeillaan puhki näyteikkunoita.
Kaikki kiiruhtivat siltaa kohti. Ensin harvat, sitten yhä useammat ja
vihdoin juoksivat he joukottain. Muutamien kauppojen ja kellarien
kohdalla pysähdyttiin, tempaistiin pullo, toinenkin ja paettiin
eteenpäin.

"Ja sitten 20 minuuttia myöhemmin näkyi tiellä kaksi


polkupyöräilijää, teräskypärä päässä — varovaisesti pälyen
ympärilleen.

"Ensimäiset saksalaiset!

"Heitä seurasivat jalan 28:nnen Reinin rykmentin miehet kivääri


käsillä valmiina, mutta nauraen, leikkiä laskien. Toista tietä tuli uusia
joukkoja pyrkien pääkatua myöten torille.

"Yhtäkkiä kuulat rätisivät. Venäläiset ampuivat siltaa


konekivääreillä. Kuulat lensivät talojen nurkkiin. Sitten valtava
räjähdys. Aa-joen silta lensi ilmaan.

"Mutta sillä aikaa vyöryi mahtava virta kaikkia aselajeja


Grünhöfsche- ja Katolische Strasse'a" myöten kaupunkiin. Valtava,
ihmeellinen näky, suuri ja voittoisa Saksan armeija.
"Ja Mitaun asukkaat, harvat jälelle jääneet, he tempasivat ikkunat
auki ja kiiruhtivat kadulle. 'He ovat täällä, he ovat täällä!' Vuori vyöryi
joka rinnalta, hengitettiin taas vapaasti, turvan ja suojan tunne
palasi jälleen tuskan ja kauhun hetkien jälkeen.

"'Max' ja 'Germania', suuret mörssärit, kuletettiin torille ja sieltä ne


lähettivät pakeneville venäläisille jylisevät terveiset, niin että katot
vapisivat.

"Oli Mitaun suurin päivä 1/8 1915."

Edellisestä selviää baltilaisen kansanaineksen suhde


sotatapahtumiin. Ollen germaanista syntyperältään, kieleltään ja
sivistykseltään, ollen hallitseva aines maassa, asuen komeissa
maakartanoissaan, "hoveissa", eläen henkisesti erillään muusta
maan asutuksesta se toivoi vain Kuurinmaan yhdistämistä Saksaan ja
saksalaisen hengen voittoa Itämerenmaissa.

LEIRIELÄMÄÄ.

Jääkäripataljoonan harjoitukset jatkuvat Mitaun ympäristössä. Vaikka


olemme 1 1/2 peninkulman päässä etulinjasta, kuuluu tykkien jyske
rintamalta selvästi, jopa iltaisin konekiväärien rätinä. Saksalaiset
naapuritaloissa kummastelevat jääkäreitä, jotka eivät ymmärrä
eivätkä puhu saksaa, vaan mongertavat vierasta kieltä. Kullakin
joukolla on määrätty alue, minkä ulkopuolelle ilman lupalippua ei saa
mennä.
Eräänä iltana 2 jääkäriä tietämättöminä tavoista lähtee rajan
ulkopuolelle komeaan koivumetsään vastoja tekemään lauantai-
illaksi. On valmistettu oikein suomalainen sauna. Toinen jääkäri on
paraillaan puussa katkomassa lehviä, kun saksalainen yliluutnantti,
jolle alue kuuluu, saapuu paikalle, alkaa jylisevän nuhdesaarnan
lihavalle hyvinvoivalle maalaispojalle, joka suorana kuin kynttilä
seisoo koivun juurella:

— Sie Esel — zum Teufel, Donnerwetter!!!

Toveri tuon pahan ilman noustessa piiloutui syvälle oksien


siimekseen korkeudessa.

Mies, joka saarnan saa, ei ymmärrä sitä eikä puhu sanaakaan.

Vihdoin yliluutnantti ärjäsee:

— Mistä te olette kotoisin, te kun ette ymmärrä edes saksaa?

Aivan hätääntyneenä luo jääkäri katseensa korkeuteen, jossa


kielitaitoinen toverinsa lymyy puun oksien siimeksessä.

— Tule, kuule Jannu, nyt alas puusta, muuten käy huonosti.

— Ahaa, onko siellä puussa vielä toinen yhtä suuri lurjus.

Jääkäri tuolla yläilmoissa tekee tanakan oksan varassa


perusasennon.

— Zu Befehl, Herr Oberleutnant! (Kuten herra yliluutnantti


käskee!)

— Mutta ketä te olette, puolalaisia, bulgarialaisia, — hottentotteja?


— Suomalaisia! herra yliluutnantti.

— Suomalaisia! Miten Herran nimessä te olette tänne päässeet?

Yliluutnantille alkaa selvitä suuri valtiollinen salaisuus. Nyt hän


puhuu asiat rauhallisesti, hymyilee salaperäisesti kulkien poikien kera
joukkueen majoituspaikalle.

— Lähdettekö etulinjaan myöskin? hän kyselee.

— Tietysti.

— Venäläisiä vastaan?

— Aivan niin.

— No hyvä, me olemme aseveljiä. Minä tulen mukananne


Suomeen! Näkemiin!

*****

8/6. Ihana aamu Kuurinmaalla. Miehet istuvat omatekoisten liesien


äärellä, keittävät perunoita ja lihaa. Kaikkialla savuavat pienet tulet
ja ruoka-astiat höyryävät. Eräs ylioppilas yrittää laittaa paistia, mutta
rasva syttyy palamaan ja ahneet liekit nuolevat sen kokonaan
onnettoman katsojan nenän edestä.

Löytämistään sorsan munista laittaa eräs herkkusuu "Spiegeleir"-


laitosta, jota pari pohjalaista ahneesti vilkuilee uhaten
lohdutuksekseen Venäjällä lyödä pataan kokonaiset lehmät ja
lampaat.

Toinen joukkue on uimaan menossa Aa-joen rannalle. Rantatöyräs


on täynnä ruskeita alastomia vartaloita. Joella ei ole paljonkaan
liikettä. Sotilasten hitaasti soutamat lautat ja veneet lipuvat niemen
taa, mutta milloin uima-aika sattuu, on koko suvanto yhtenä
polskinana. Joskus koko rivi ketjuna syöksyy hurjaa juoksua
kuohuihin, päristelee ja porisee kuin välkkyvä, kuohuva koski satoine
hyrskyineen ja salakareineen.

Äkkiä kajahtaa huuto:

Lentokone!

Surinaa kuuluu ilmassa. Ystävä vai vihollinen?

Kaksitaso surisee kaukana metsän yllä pienenä mustana


herhiläisenä.

Saksalainen tykki jymähtää.

Lentokoneen lähelle ilmestyy kaunis, valkea savupilvi ja hetken


kuluttua kuuluu hiljainen räjähdys.

Vihollinen on keksitty. Yhä useampia savupalloja välähtää


kirkkaassa ilmassa. Ne näyttävät ajavan takaa lentäjää.

Nyt! Aivan koneen perässä räjähtää. Tuli kiihtyy. Lentokone


näyttää maasta katsoen olevan hukassa. Odotamme joka hetki sen
syöksyvän maahan. Äkkiä tekee lentäjä valtavan kaaren ilmassa
syöksyen vinoon maata kohti.

— Se on mennyttä kalua! huudetaan.

Mutta hämmästykseksemme se nousee taas liitäen ylpeänä kuin


suuri haukka pilven alla rauhallisesti yli Mitaun, kääntyy ja palaa
vahingoittumatta pitkän valkean savupallorivin takaa-ajamana
takaisin omille mailleen.

Näytelmä oli mielenkiintoinen, ensimäinen silminnähty


sotatapahtuma. Kuitenkin tuntui jonkinlainen pettymys mielessä.
Jokainen oli toivonut saavansa nähdä koneen granaatin
murskaamana syöksyvän maahan. Vasta sitten kun tuo näytelmä
joka päivä uudistui, jopa useita kertoja päivässä, älysimme miten
vaikeata on osata lentokoneeseen tykillä.

Iltapäivällä oli suuri paraati. 8:nneu armeijan komentaja kenraali


von
Below tarkastaa joukkomme.

Pataljoona kokoontuu maantien varrelle laajalle vihreälle


ruohokentälle, järjestäytyen rintama maantietä vastaan. Aluksi on
jälleen ankara pukujen tarkastus. Auta armias, jos saappaissa on
tomun hiventäkään. — Alles muss tipp topp sein!

Majuri kävelee hermostuneena edestakaisin, harjoituttaa pari


kolme kertaa kiväärin olalle ja jalalle viemistä. Rivit ojennetaan joka
taholle. Upseerit ja aliupseerit ärjyvät kukin alaisilleen:

— Toinen ja kolmas mies kantapäät taaksepäin — — — ei niin


paljon, ettehän näe sieltä muuta kuin takarivin, no niin — — —
nenät ylös! — — — kuuletteko — — — mutta leuka sisään! Mitä te
mukisette? Olenko minä teiltä mitään kysynyt?

Automobiili tiellä.

— Jägerbataillon 27. — Stillgestanden! komentaa majuri kimeällä


äänellä. Puolitoista tuhatta miestä seisoo jännittyneinä, mykkinä,
hiljaa odotellen seuraavaa _juhla_komentoa.

— Viides mies, painakaa perää, kuuletteko, sähisee vielä


hampaittensa raosta joku virkaintoinen joukkueenjohtaja.

— Das Gewehr über. Augen rechts!

Eversti saapuu. Majuri ilmoittaa pataljoonan.

Taas komennus: Augen gerade — aus. Gewehrab. Rührt euch!

Pataljoonassa käy sekava liike. Kaikki huokaavat helpotuksesta.


Odotetaan taas, yhä odotetaan. Hermostus kasvaa.

Taas näkyy auto tiellä. Nyt — — — autossa välkkyy punaista.

— Kenraali, kenraali! käy suhina riveissä.

— Suu kiinni! Nicht quatschen da! ärjyy joku terävästi


puoliääneen.

— Jägerbataillon 27! — Stillgestanden!

Nopea sävähdys, ja pataljoona näyttää kokoelmalta historiallisia


muistopatsaita. Joku tottumaton horjahtaa hiukan, mutta saa
pukkauksen kylkeensä ja muuttuu liikkumattomaksi pelkästä
kauhusta.

Sääski istuu erään sankarin nenän orrelle alkaen ahneesti imeä


verta. Mies vääristelee naamalihaksiaan ja huulien välissä sihisee
pidätettyjä kiroussanoja, mutta kättään ei kukaan uskalla kohottaa.

— Guten Tag Jäger! tervehtii kenraali.


— Guten Tag, Eure Exellenz! vyöryy kuin ukkosen jyrinä yli
pataljoonan.

Torvista kajahtaa kansallislaulu. Maammelaulu.

Kenraali kulkee hitaasti rivien ohitse, katsoo tuikeasti joka miehen


silmiin ja näkee — suomalaiset naamat hartaina, synkän päättävinä
— nuo jykevätekoiset pohjalaiskasvot. Kun kenraali on ehtinyt
kolmanteen mieheen vasemmalle, on sotilaan äkisti nykäistävä
nenänsä suoraan. Vihdoin sitten "Exellenz" pääsee rivien päähän.

Pataljoona järjestäytyy paraatimarssiin joukkueittain. Toimituksen


juhlallisin hetki lähestyy. Taas tuntuu omituinen hermostuttava
kutkutus lihaksissa.

— Muistakaa nyt pojat. Marssikaa hyvin! Jalat korkealle! Katsokaa


kenraalia! Jumalauta!

Ensi joukkueen kiväärit jo liikkuvat.

Valmiit!

— — — drei, fünf, sieben — — j.n.e. laskee siipialiupseeri


suupielet vavahdellen.

Frei — — — weg!

Jalat nousevat pitkin riviä yhtaikaa. Jännitys on äärimmillään.


Ajatus sekaantuu. Kuin unessa tunnen eteneväni rivin mukana.

Miten käynee? Tuleeko riviin aukkoja?

Nyt ollaan kenraalin kohdalla. Joka mies pullistaa rintaansa ja


tähystää kaamein ilmein kenraalia. Jumalan kiitos, ohi ollaan. Vasen

You might also like