You are on page 1of 21

Introduction to Programming

Talking Points
• Course Goals and Structure
• Syllabus
• Introductions
• Computers
• UNIX
• Editors
• First C program
• Assignments
Course Goals and Structure
• Demystify C ;-)
• Impart good design, software engineering, algorithm, and
data structure techniques for using C effectively
• Emphasis is on practicing these techniques while also
addressing C language concepts and constructs
• The class is heavily example-driven
• The class will combine lectures, interactive discussions,
and hands-on exercises
• It is very important to practice reading and writing C
Computers
• What is a computer?
– A computational device
– Logical decisions billions of times faster than humans
– Hardware
• keyboard, screen, disks, memory, CPU
– Software
• email, word processing, spreadsheets, OS
Computer Organization
• Input unit
– keyboard, microphone
• Output unit
– screen, printer
• Memory unit
– Random Access Memory (RAM)
– short-term, rapid access, low capacity warehouse
• Arithmetic and logic unit
– calculations, comparisons
• Central Processing Unit (CPU)
– coordinator, administrator
• Secondary storage unit
– disks, tapes
– long-term, slow access, high capacity warehouse
Computer Architecture

CPU Memory I/O

Program
Control Unit

ALU
Computing Modes
• Batch Processing • Personal computer (PC)
– one job at a time – standalone units
• Multiprogramming • Distributed computing
– many jobs simultaneously – workload distributed over
• Timesharing networks
– multiple jobs, multiple • Client/Server
users – client machine provides
user interface
– server machine provide
computational power and
storage location
UNIX
• Time sharing operating system
– computer’s resource controller and manager
• file and device management
• multi-user, interactive
• Common commands
– ls (list files)
– less (browse through a text file)
– mv (move or rename a file)
– cp (copy a file)
– rm (delete a file)
– man (help on a command)
– other commands: wc, grep, sort, diff
Directories in UNIX

• Manipulating directories
– pwd (present working directory)
– cd (change current directory)
– mkdir (make a directory)
– rmdir (remove directory)
Funnies….
• % make love
• % got a light?
• % man: why did you get a divorce?
• % rm God
• % ar t God
• % ar r God
• % ^How did the sex change operation go?
Editors
• EMACS and VI
• Using Editors
– files
• opening
• saving
• switching buffers
– editing
• undo
• moving around
• cutting and pasting
• searching and replacing
Programming Languages
• Machine Language
– machine/hardware dependent
– Too hard to program in
• Assembly Language
– English-like operations (e.g., load, store, add)
• High-level languages
– single statement can accomplish substantial tasks
– English-like statements with mathematical notations
C Programming Environment

Preprocess/
Compile/
Link
Load/
Edit Run

Editor test.c a.out CPU


First C Program

/* My first simple C program */

Comments
main ()
All C programs have a main function;
{ they also start at main
printf (“Welcome to C!\n”);
Function to print to screen
}
Braces indicate start What to print End of
and end of main statement
End of line
Textbooks and Recommended
Reading Material
• The C Programming Language, 2nd Edition, Brian
Kernighan and Dennis Ritchie, Addison-Wesley 1988
• Also called K&R (I and II)
• A very well written description of the C programming language by
the original language designers
– Strengths
• Very useful examples
• Very few mistakes and/or typos
• Very concise (i.e., good for a reference)
– Weaknesses
• Very terse (often difficult to learn C using this book alone)
Textbooks and Recommended
Reading Material (continued)
• C Traps and Pitfalls, Andrew Koenig, Addison-
Wesley
• Illustrates many common errors that can occur when working
with C and how to avoid many of them
– Strengths
• Extremely practical
– Weaknesses
• Not a tutorial or reference manual (i.e., use as supplementary
reading)
Textbooks and Recommended
Reading Material (continued)
• The C Standard Library, P. J. Plauger
• Describes in great detail the interfaces and behaviors of the ANSI C standard library
• In addition, it also provides the source code, so you can learn how to write all those
functions!
• A Book on C, Kelly and Pohl
• A much simpler introduction/tutorial to the C programming language
• Provides many examples and analyzes them via dissection.
– Strengths
• For beginning programmers, it may be easier than K&R to learn with
– Weaknesses
• Not as concise and/or comprehensive as K&R

You might also like