








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Introduction to C
Typology: Lecture notes
1 / 48
This page cannot be seen from the preview
Don't miss anything!









































We are going
(^) to learn a language called C.
C is a very flexible and powerful
the early 1970s.programming language originally designed in
specially designed for this.operating system was written in, and wasIt is famous as the language the UNIX
that field and it is currently very popular.However its use has now spread way beyond
In programming
terms this means is that C
programming languages.lacks some safety features provided by other
This makes the language much more flexible.
However, if
I do something stupid C will not
I do with a safer language.crashing the computer with a C program thanstop me, so I have a much greater chance of
Linking is
when all the various portions of
something which can be run.your program are brought together to form
pieces of code from a library.process is that it allows us to reuse standardThe reason that we have the additional linking
common to lots of other programs.Many things your program will do are
Once the
linker has finished you are left with
you run this your program gets control!a free standing file which is your program. If
a compiled version of this code into a library.program, a much more efficient way is to putdoes this every time you compile yourRather than compile the program code which
when it creates your program.then loads the relevant part from the libraryparticular function you want to use, the linkerYour program just contains a reference to the
A program
is the thing that you write to
perform a particular task.
It will
(^) actually be a file of text, often called a
A source file contains three things :source file. This is what the compiler acts on.
Instructions to the compiler
hold the data to be stored and manipulated.Information about the structures, which will
Instructions which manipulate the data.
Programs work
by processing data. The data
the program processes it.has to be stored within the computer whilst
All computer languages support variables of
one form or another. A
variable
is simply a
the program runs.named location in which a value is held whilst
a particular bank customer.structure could hold all the information abouthold more than one item, for example a singleC also lets you build up structures which can
A
statement
is
an
instruction
to
perform
one
particular
operation,
for
example
add
two
numbers together and store the result.
You
give
a
name
to
each
function
that
you
save_file.function fit what it does, for example menu orcreate, and you try to make the name of the
The
language
actually
runs
program
by
looking for a function with a special name,
main
endsrunning, and when main finishes, your programThis function is called when your program starts
The good news
(^) about C is that you can write
quite easily.access low-level facilities in your computervery "close to the hardware“, so that you cancode, which runs quickly, and your program is
The use of
compiler directives to the pre-
several different types of computer.version of a program which can be compiled onprocessor make it possible to produce a single
systems.versions of C - they can be used on allThe function libraries are standard for all
statements.express exactly what you want to do in very fewC allows you to write very terse code. You can
harder to understand.But it has the side effect of making them much
what each part is supposed to do.At the time you write the code you know exactly
Several months you will need time to
"get back
inside it."
at all.Other people may not be able to understand it
Perhaps the
(^) best way to start looking at C is to jump
{ void main ( void )#include <stdio.h>straight in with our first ever C program, so here it is:
printf ( "The area of glass is : %f metres.\n",area )wood_length = 2 * ( height + width ) * 3.25 ;area = 2 * height * width ;scanf ( "%f", &width ) ;scanf ( "%f", &height ) ;float height, width, area, wood_length ;
;
printf ( "The length of wood is : %f
} feet.\n",wood_length ) ;