Page 1
Edition 4.1 The GNU C Programming Tutorial Mark Burgess Faculty of Engineering, Oslo College Ron Hale-Evans
Edition 4.1 of an introductory C programming tutorial for readers with basic computer literacy and access to a GNU system such as GNU/Linux. The supplied excerpt covers GCC compilation, program structure, functions, variables, scope, operators, parameters, pointers, decisions, loops, preprocessor directives, libraries, arrays, and strings. It includes code examples and chapter exercises. Originally written by Mark Burgess, the tutorial was subsequently revised by Ron Hale-Evans and released under the GNU Free Documentation License.
The first 5 pages, shown as text so search engines and readers can find this document.
Edition 4.1 The GNU C Programming Tutorial Mark Burgess Faculty of Engineering, Oslo College Ron Hale-Evans
Copyright c© 2002 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; there being no Invariant Section, with the Front-Cover Texts being “A GNU Manual”, and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License”. (a) The FSF’s Back-Cover Text is: “You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.”
Preface xi Preface This book is a tutorial for the computer programming language C. Unlike BASIC or Pascal, C was not written as a teaching aid, but as a professional tool. Programmers love C! Moreover, C is a standard, widely-used language, and a single C program can often be made to run on many different kinds of computer. As Richard M. Stallman remarks in GNU Coding Standards, “Using another language is like using a non-standard feature: it will cause trouble for users.” (See http://www.gnu.org/prep/standards_toc.html.) Skeptics have said that everything that can go wrong in C, does. True, it can be unfor- giving, and holds some difficulties that are not obvious at first, but that is because it does not withhold its powerful capabilities from the beginner. If you have come to C seeking a powerful language for writing everyday computer programs, you will not be disappointed. To get the most from this book, you should have some basic computer literacy — you should be able to run a program, edit a text file, and so on. You should also have access to a computer running a GNU system such as GNU/Linux. (For more information on GNU and the philosophy of free software, see http://www.gnu.org/philosophy/.) The tutorial introduces basic ideas in a logical order and progresses steadily. You do not need to follow the order of the chapters rigorously, but if you are a beginner to C, it is recommended that you do. Later, you can return to this book and copy C code from it; the many examples range from tiny programs that illustrate the use of one simple feature, to complete applications that fill several pages. Along the way, there are also brief discussions of the philosophy behind C. Computer languages have been around so long that some jargon has developed. You should not ignore this jargon entirely, because it is the language that programmers speak. Jargon is explained wherever necessary, but kept to a minimum. There is also a glossary at the back of the book. The authors of this book hope you will learn everything you need to write simple C programs from this book. Further, it is released under the GNU Free Documentation License, so as the computers and robots in the fantasies of Douglas Adams say, “Share and Enjoy!” The first edition of this book was written in 1987, then updated and rewritten in 1999. It was originally published by Dabs Press. After it went out of print, David Atherton of Dabs and the original author, Mark Burgess, agreed to release the manuscript. At the request of the Free Software Foundation, the book was further revised by Ron Hale-Evans in 2001 and 2002. The current edition is written in Texinfo, which is a documentation system using a single source file to produce both online information and printed output. You can read this tutorial online with either the Emacs Info reader, the stand-alone Info reader, or a World Wide Web browser, or you can read it as a printed book.
The advantages of C 1 1 Introduction What is a high-level language? Why is C unusual? Any sufficiently complex object has levels of detail; the amount of detail we see depends on how closely we scrutinize the object. A computer has many levels of detail. The terms low level and high level are often used to describe these layers of complexity in computers. The low level is buried in the computer’s microchips and microcircuits. The low level is the level at which the computer seems most primitive and mechanical, whereas the high level describes the computer in less detail, and makes it easier to use. You can see high levels and low levels in the workings of a car. In a car, the nuts, bolts, and pistons of the low level can be grouped together conceptually to form the higher-level engine. Without knowing anything about the nuts and bolts, you can treat the engine as a black box: a simple unit that behaves in predictable ways. At an even higher level (the one most people use when driving), you can see a car as a group of these black boxes, including the engine, the steering, the brakes, and so on. At a high level, a computer also becomes a group of black boxes. C is a high-level language. The aim of any high-level computer language is to provide an easy, natural way to give a list of instructions (a computer program) to a computer. The native language of the computer is a stream of numbers called machine language. As you might expect, the action resulting from a single machine language instruction is very primitive, and many thousands of them can be required to do something substantial. A high-level language provides a set of instructions you can recombine creatively and give to the imaginary black boxes of the computer. The high-level language software will then translate these high-level instructions into low-level machine language instructions. 1.1 The advantages of C C is one of a large number of high-level languages designed for general-purpose program- ming, in other words, for writing anything from small programs for personal amusement to complex industrial applications. C has many advantages: • Before C, machine-language programmers criticized high-level languages because, with their black box approach, they shielded the user from the working details of the com- puter and all its facilities. C, however, was designed to give access to any level of the computer down to raw machine language, and because of this, it is perhaps the most flexible high-level language. • C has features that allow the programmer to organize programs in a clear, easy, logical way. For example, C allows meaningful names for variables without any loss of effi- ciency, yet it gives a complete freedom of programming style, including flexible ways of making decisions, and a set of flexible commands for performing tasks repetitively (for, while, do).
2 Chapter 1: Introduction • C is succinct. It permits the creation of tidy, compact programs. This feature can be a mixed blessing, however, and the C programmer must balance simplicity and readability. • C allows commands that are invalid in other languages. This is no defect, but a powerful freedom which, when used with caution, makes many things possible. It does mean that there are concealed difficulties in C, but if you write carefully and thoughtfully, you can create fast, efficient programs. • With C, you can use every resource your computer offers. C tries to link closely with the local environment, providing facilities for gaining access to common peripherals like disk drives and printers. When new peripherals are invented, the GNU community quickly provides the ability to program them in C as well. In fact, most of the GNU project is written in C (as are many other operating systems). For the reasons outlined above, C is the preeminent high-level language. Clearly, no language can guarantee good programs, but C can provide a framework in which it is easy to program well. 1.2 Questions for Chapter 1 1. Explain the distinction between high levels and low levels. 2. What is a “black box”? 3. Name a few advantages to programming in the C language.
Doxxly editorial guide
This guide helps you understand the scope of The GNU C Programming Tutorial before or alongside reading the original document. It is based on the catalogue record, credited creator, source, classification and topics shown on this page. It does not replace the original work and does not invent claims about passages that Doxxly cannot verify.
The GNU C Programming Tutorial is a 300-page documentcredited to Hana W. Cressley. Edition 4.1 of an introductory C programming tutorial for readers with basic computer literacy and access to a GNU system such as GNU/Linux. The supplied excerpt covers GCC compilation, program structure, functions, variables, scope, operators, parameters, pointers, decisions, loops, preprocessor directives, libraries, arrays, and strings. It includes code examples and chapter exercises. Originally written by Mark Burgess, the tutorial was subsequently revised by Ron Hale-Evans and released under the GNU Free Documentation License. It appears in the Education & Learning collection, which groups it with other material that readers may use for comparison and further study.
The item can be approached in several ways. A reader looking for a quick orientation can begin with the free five-page preview, inspect the page structure and use the metadata to judge relevance. Someone undertaking deeper research can work through the complete file, search its indexed text, record useful page references and compare its treatment of C programming, GNU, GCC, GNU/Linux, Programming tutorial, Free documentation, Pointers, Arrays, Strings with the related resources linked below.
Rather than reducing the work to a single claim, this page treats it as a source that should be read in context. The title, creator, publication source, licence and format all help explain what kind of evidence it may offer. Readers should distinguish the original author's statements from Doxxly's catalogue description, and should cite the original edition when using the material in academic, professional or published work.
The catalogue connects this document with C programming, GNU, GCC, GNU/Linux, Programming tutorial, Free documentation, Pointers, Arrays, Strings. These terms offer practical entry points rather than a substitute for close reading. Start by identifying the definitions, examples, arguments, tables or visual explanations attached to each topic. Then note where the creator draws connections, makes distinctions or moves from background material to a conclusion, recommendation, calculation or narrative development.
A useful reading method is to separate description from interpretation. First record what the item actually presents: names, headings, figures, formulas, quotations or stated propositions. Next consider why those details matter within the whole work. Finally compare them with another source from the same subject area. This process helps turn a long digital file into evidence that can be evaluated rather than merely skimmed.
The following is an editorial content guide based on the verified catalogue topics. It is not represented as the original author's formal table of contents. Use it to organise notes while moving through the 300 pages in the player.
Use this section of the reading guide to identify how C programming appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
Use this section of the reading guide to identify how GNU appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
Use this section of the reading guide to identify how GCC appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
Use this section of the reading guide to identify how GNU/Linux appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
Use this section of the reading guide to identify how Programming tutorial appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
Use this section of the reading guide to identify how Free documentation appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
Use this section of the reading guide to identify how Pointers appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
Use this section of the reading guide to identify how Arrays appears in The GNU C Programming Tutorial, note important terms, and connect the subject to the wider purpose of the work.
When a heading in the original differs from this guide, follow the original heading in your citation. Page numbers can also vary between editions. Doxxly's direct page field is useful for navigation, but formal references should include the title, creator, source and edition details available in the file itself.
Doxxly credits Hana W. Cressley as the author or creator of The GNU C Programming Tutorial. This page does not add an unverified biography, job title or institutional affiliation. The attribution is preserved so readers can distinguish the creator from the hosting library and follow the original record when an external author link is available.
Author context matters because a work reflects a particular purpose, audience and point of view. Before relying on the material, consider what the creator set out to explain, when the source was produced and whether later research or revised guidance should also be consulted. For literature and philosophy, compare translations and editions; for technical material, check whether a newer version has superseded the one shown here.
The recorded source for this item is it.uc3m.es. Doxxly provides access and discovery tools but does not claim to be the original publisher unless explicitly stated. Source links, creator attribution and the recorded Publicly available file collected for editorial review licence are displayed to help readers assess provenance and permitted use.
Provenance is especially important for reports, standards, presentations and working spreadsheets. Check the original source for amendments, supporting files and current policy. A trustworthy research workflow keeps the source URL with any notes or downloaded copy, verifies important figures against the original, and avoids treating an archived document as automatically current.
Visit it.uc3m.esBegin with the title and opening pages, then use the guide above to decide whether to read sequentially or move to a particular topic. The Doxxly player provides previous and next navigation, a direct page field, zoom steps, fit-to-width and fit-to-page modes, rotation and fullscreen. These controls are useful when a page contains small type, a wide table, an image, a scanned layout or a dense sequence of notes.
The first five pages are open to every visitor. A plan unlocks the complete item and full-document search. Search is best used for distinctive names, technical terms or short phrases; broad words can produce too many possible contexts. When you find a useful passage, read the surrounding pages so that a sentence, chart or formula is not separated from its explanation.
If downloading is enabled, members can obtain the original PDF file. Keep the original format when formulas, slide sequencing, pagination or layout carries meaning. Respect the Publicly available file collected for editorial review terms displayed on this page, and use the rights-report link if you believe the attribution or availability needs review.
As you read The GNU C Programming Tutorial, ask which audience the creator addresses, what problem or idea organises the work, what evidence is presented, and which assumptions remain unstated. Note whether important terms are defined consistently and whether examples represent a broader pattern or a narrow case. For quantitative material, record units, time periods, formulas and data sources. For interpretive material, separate the creator's language from your own summary.
A second set of questions concerns relevance today. Which parts remain durable, which depend on their historical or institutional setting, and what would need confirmation from a newer source? Following the tags and the Education & Learning collection can reveal useful comparisons. Agreement between sources can strengthen confidence, while disagreement can point to changing definitions, methods, evidence or priorities.
Finally, decide what you need from the item: background knowledge, a quotation, a worked example, a model, a visual explanation or a starting bibliography. That purpose should guide the depth of reading and the notes you keep. Doxxly helps locate and navigate the source; careful interpretation remains the reader's responsibility.
Practical answers about reading, downloading and understanding this document on Doxxly.
Cleo G. Vance
Lior D. Dunmore
Kaya J. Vance
Yusuf Y. Grayling
Bram Q. Oakfield
Zora C. Cressley