Академический Документы
Профессиональный Документы
Культура Документы
Engr. Muhammad Usman Assistant Professor, CSE UET Mardan Campus engrosman@yahoo.com
1
Program structure and functions Pointers & Arrays Dynamic Memory Allocation Structures and Unions Input and Output
File handling
2
Suggested Textbooks
The C Programming Language (2nd edition - ANSI C), Brian W. Kernighan and Dennis M. Ritchie, Prentice Hall Let us C, Yashwant Kanitkar Practical C Programming, 3rd Edition, Steve Oualline
Learning
Is best done by doing For a skill like programming, swimming or riding a bicycling you can not learn by listening or watching If you help someone, NEVER take over the keyboard. Try to give the smallest of hints.
Course Objectives
Objectives of this course are three fold
To appreciate the need for a programming language To introduce the concept and usability of the structured programming methodology To develop proficiency in making useful software using the C language
Machine language
Computers understand only machine language.
Every processor has its own machine language. Basically looks like a sequence of 1s and 0s. Very inconvenient to work with and non intuitive.
10
11
Low-level languages
closer to hardware more efficient (but also dangerous!)
12
13
14
Program
A precise sequence of steps/instruction to solve a particular problem
The instructions are executed sequentially. No instruction is executed before the previous has been completed. Each instruction has a numerical code.
15
Examples of instructions
Load data (from an address in the memory). Store data (on an address in memory). Add two numbers. If two numbers are equal, jump to another part of the program. Instructions are numbers!
16
Why C?
Selection of a programming language is an old debate in computing.
For application development, it is a very hot debate. But for system programming very few experts argue for language other than C Reason is simple: C is closest to hardware. C tends to execute faster than code written in other languages.
Historically, Linux kernel is developed in C Unix OS itself in C Device drivers and a great deal of software are almost always written in C C still good for efficient applications that need to use low-level features of C (data compression, graphics, compilers, operating systems, systems programming)
17
History of C
1972: The C programming language developed by Dennis Ritchie. He wanted to design a better Operating System.
MULTICS a better alternative for Punched Cards UNIX (first written in Assembly)
Joint committee from University of London Computer Unit and Mathematical laboratory at Cambridge decided to design a language that could be
High (wouldnt be tied to a particular computer) as well as low level (manipulation of specific bits) The result was Combined Programming Language (CPL) Further attempts were BCPL, B (by Thompson), and finally C (by Ritchie)
18
1973: C used to rewrite the Unix operating system. 1978: Kernighan and Ritchie set the first standard of C: K&R standard 1989: the American National Standards Institute adopted the ANSI C standard 1999: New ANSI standard (also known as C99)
20
DMR (Contd)
On April 21, 1999, Thompson and Ritchie jointly received the 1998 National Medal of Technology from President Bill Clinton for co-inventing the UNIX operating system and the C programming language In 2010 Dennis Ritchie, along with Ken Thompson, was awarded the Japan Prize for Information and Communications for the pioneering work in the development of Unix operating system Ritchie was the head of Lucent Technologies System Software Research Department when he retired in 2007
21
Hello world, a program originally written by Brian Kernighan of Bell Labs in "A Tutorial Introduction to the Language B
22
Strengths of C
Efficiency Portability Power Flexibility
not just for systems programming!
23
C is a procedural language
It enables the user to create new instructions (procedures) from existing ones. Instead of re-writing the same code over and over again, write it once and call it when needed.
24
25
How do we compile?
A special program the compiler translates computer language to machine language There are many compilers in the market
For MS Windows
Microsoft Visual C++ 6.0 or 2008 Express Edition Microsoft Visual Studio 2008 or 2010 Professional Edition Turbo C
For Unix/Linux
GCC or CC
26
Getting Started
Alphabets Words Sentences Paragraph
English Language
Instructions
Program/ Code
27
C Language
28
29
30
31
32
33
34
35
36
37
38
39
40
Exercise
Write, compile and run a program that prints the name of your department in two lines (one word in each separate line).
42