C Programming Tutorial.pdf
(
2297 KB
)
Pobierz
C Programming Tutorial
Node:Top, Next:Preface, Previous:(dir), Up:(dir)
C Programming Tutorial (K&R version 4)
This is a C Programming Tutorial for people who have a little experience with an interpreted programming
language, such as Emacs Lisp or a GNU shell.
Edition 4.02
Copyright © 1987,1999 Mark Burgess
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this
permission notice are preserved on all copies.
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
Preface:
Introduction:
Reserved words & example:
Operating systems:
Libraries:
Programming style:
Form of a C program:
Comments:
Functions:
Variables:
Parameters:
Scope:
Preprocessor:
Pointers:
Standard Output and Standard Input:
Assignments Expressions and Operators:
Decisions:
Loops:
Arrays:
Strings:
Putting together a program:
Special Library Functions and Macros:
Hidden Operators:
More on Data Types:
Machine Level Operations:
Files and Devices:
Structures and Unions:
http://www.iu.hio.no/~mark/CTutorial/CTutorial.html (1 of 280)17/07/2003 19:49:43
C Programming Tutorial
q
q
q
q
q
q
q
q
q
q
q
Data structures:
Recursion:
Example Programs chapter:
Errors and debugging:
Summary:
reserved words list:
Comparisons
:
Character Conversion Table:
Emacs style file:
Answers to questions:
Index:
Node:Preface, Next:Introduction, Previous:Top, Up:Top
Preface
Every program is limited by the language which is used to write it. C is a programmer's language. Unlike BASIC or
Pascal, C was not written as a teaching aid, but as an implementation language. C is a computer language and a
programming tool which has grown popular because programmers like it! It is a tricky language but a masterful one.
Sceptics have said that it is a language in which everything which can go wrong does go wrong. True, it does not do
much hand holding, but also it does not hold anything back. If you have come to C in the hope of finding a powerful
language for writing everyday computer programs, then you will not be disappointed. C is ideally suited to modern
computers and modern programming.
This book is a tutorial. Its aim is to teach C to a beginner, but with enough of the details so as not be outgrown as the
years go by. It presumes that you have some previous aquaintance with programming -- you need to know what a
variable is and what a function is -- but you do not need much experience. It is not essential to follow the order of
the chapters rigorously, but if you are a beginner to C it is recommended. When it comes down to it, most languages
have basically the same kinds of features: variables, ways of making loops, ways of making decisions, ways of
accessing files etc. If you want to plan your assault on C, think about what you already know about programming
and what you expect to look for in C. You will most likely find all of those things and more, as you work though the
chapters.
The examples programs range from quick one-function programs, which do no more than illustrate the sole use of
one simple feature, to complete application examples occupying several pages. In places these examples make use
of features before they have properly been explained. These programs serve as a taster of what is to come.
Mark Burgess. 1987, 1999
This book was first written in 1987; this new edition was updated and rewritten in 1999. The book was originally
published by Dabs Press. Since the book has gone out of print, David Atherton of Dabs and I agreed to release the
http://www.iu.hio.no/~mark/CTutorial/CTutorial.html (2 of 280)17/07/2003 19:49:43
C Programming Tutorial
manuscript, as per the original contract. This new edition is written in Texinfo, which is a documentation system
that uses a single source file to produce both on-line information and printed output. You can read this tutorial
online, using either the Emacs Info reader, the standalone Info reader, or a World Wide Web browser, or you can
read this same text as a typeset, printed book.
Node:Introduction, Next:Reserved
words & example,
Previous:Preface, Up:Top
Introduction
What is C? What is it for? Why is it special?
q
q
q
q
q
q
Levels:
Basic ideas:
The compiler:
Errors:
Use of Upper and Lower Case:
Questions 1:
Node:Levels, Next:Basic
ideas,
Previous:Introduction, Up:Introduction
High Levels and Low Levels
Any kind of object that is sufficiently complicated can be thought of as having levels of detail; the amount of detail
we see depends upon how closely we scrutinize it. A computer falls definitely into the category of complex objects
and it can be thought of as working at many different levels. The terms
low level
and
high level
are often used to
describe these onion-layers of complexity in computers. Low level is perhaps the easiest to understand: it describes
a level of detail which is buried down amongst the working parts of the machine: the low level is the level at which
the computer seems most primitive and machine-like. A higher level describes the same object, but with the detail
left out. Imagine stepping back from the complexity of the machine level pieces and grouping together parts which
work together, then covering up all the details. (For instance, in a car, a group of nuts, bolts, pistons can be grouped
together to make up a new basic object: an engine.) At a high level a computer becomes a group of black boxes
which can then be thought of as the basic components of the computer.
C is called a high level, compiler language. The aim of any high level computer language is to provide an easy and
natural way of giving a programme of instructions to a computer (a computer program). The language of the raw
computer is a stream of numbers called machine code. As you might expect, the action which results from a single
machine code instruction is very primitive and many thousands of them are required to make a program which does
anything substantial. It is therefore the job of a high level language to provide a new set of black box instructions,
which can be given to the computer without us needing to see what happens inside them - and it is the job of a
compiler to fill in the details of these "black boxes" so that the final product is a sequence of instructions in the
http://www.iu.hio.no/~mark/CTutorial/CTutorial.html (3 of 280)17/07/2003 19:49:43
C Programming Tutorial
language of the computer.
C is one of a large number of high level languages which can be used for general purpose programming, that is,
anything from writing small programs for personal amusement to writing complex applications. It is unusual in
several ways. Before C, high level languages were criticized by machine code programmers because they shielded
the user from the working details of the computer, with their black box approach, to such an extent that the
languages become inflexible: in other words, they did not not allow programmers to use all the facilities which the
machine has to offer. C, on the other hand, was designed to give access to any level of the machine down to raw
machine code and because of this it is perhaps the most flexible of all high level languages.
http://www.iu.hio.no/~mark/CTutorial/CTutorial.html (4 of 280)17/07/2003 19:49:43
C Programming Tutorial
Surprisingly, programming books often ignore an important role of high level languages: high level programs are
not only a way to express instructions to the computer, they are also a means of communication among human
beings. They are not merely monologues to the machine, they are a way to express ideas and a way to solve
problems. The C language has been equipped with features that allow programs to be organized in an easy and
logical way. This is vitally important for writing lengthy programs because complex problems are only manageable
with a clear organization and program structure. C allows meaningful variable names and meaningful function
names to be used in programs without any loss of efficiency and it gives a complete freedom of style; it has a set of
very flexible loop constructions (for,
while, do)
and neat ways of making decisions. These provide an excellent
basis for controlling the flow of programs.
http://www.iu.hio.no/~mark/CTutorial/CTutorial.html (5 of 280)17/07/2003 19:49:43
Plik z chomika:
jacek_040
Inne pliki z tego folderu:
C Programming Tutorial.pdf
(2297 KB)
Object Orientated Programming with ANSI C.pdf
(1224 KB)
Programming in C, A Tutorial.PDF
(177 KB)
Inne foldery tego chomika:
- komputer
! HTML CSS XHTML
_ Informatyka. English
_ Informatyka. Kryptologia
_ Informatyka. Prolog
Zgłoś jeśli
naruszono regulamin