Professional Documents
Culture Documents
What is C?
Logistics
MIT CSAIL
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Lecture plan
3. High-level introduction to C.
4. C philosophy: the abstract memory machine.
5. How to get started with C.
6. Wrap-up and homework.
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
Images of Wonder Woman and circuit boards removed due to copyright restrictions.
C/C++ empowerment
What is C?
Logistics
Background check
Expected knowledge
Basic data structures (linked lists, binary search trees, etc.)?
Familiarity with basic imperative programming concepts.
Other knowledge
Functional programming?
Systems programming?
Hardware?
OOP with another language?
Eunsuk Kang and Jean Yang
Goodbye
C/C++ empowerment
What is C?
Logistics
Course syllabus
Day
1
2
3
4
5
6
Date
1/19
1/20
1/21
1/22
1/23
1/24
Topic
Meet C and memory management
Memory management logistics
More advanced memory management
Meet C++ and OOP
More advanced OOP
Tricks of the trade, Q & A
Lecturer
Jean
Jean
Jean
Eunsuk
Eunsuk
Eunsuk
Goodbye
C/C++ empowerment
What is C?
Logistics
Administrivia
Homework
Daily homework to be submitted via the Stellar site.
Graded +, , or .
Homework i will be due 11:59 PM the day after Lecture i;
Goodbye
C/C++ empowerment
What is C?
Logistics
Recommended references
Books
Online resources
http://www.cprogramming.com
Goodbye
C/C++ empowerment
What is C?
Logistics
The C family
C
Developed in 1972 by Dennis Ritchie at Bell Labs.
C++
Developed in 1979 by Bjarne Stroustrup at Bell Labs.
Imperative, object-oriented language with generics.
Goodbye
C/C++ empowerment
What is C?
Logistics
Vocabulary check
Compiled, interpreted
Static, dynamic
Memory-managed
Goodbye
C/C++ empowerment
What is C?
Logistics
Typically, C is. . .
Compiled.
Imperative.
Manually memory-managed.
Used when at least one of the following matters:
Speed.
Memory.
Low-level features (moving the stack pointer, etc.).
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Level of abstraction
Directly manipulate memory
Access to memory
Memory managed
Languages
Assembly (x86, MIPS)
C, C++
Java, C, Scheme/Lisp, ML
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
Control/Status
Controller
IR
ALU
Registers
PC
I/O
Memory
C/C++ empowerment
What is C?
Logistics
array.
Access heap using special
pointer syntax.
The whole program has
Addr.
..
.
Contents
..
.
0xbee
0xbf4
..
.
0xbeef
0xfeed
..
.
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
Goals
Want to allow the program to be able to designate chunks of
C support
Standard library (stlib.h) has malloc and free functions.
C/C++ empowerment
What is C?
Logistics
the stack.
Goodbye
C/C++ empowerment
What is C?
Logistics
Stack
Heap
Bss
Uninitialized variables
Data
Initialized variables
Text
Instruction
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Using C
/ H e a d e r s t o i n c l u d e . /
i n t main ( ) {
p r i n t f ( Hello world ! ) ;
Goodbye
C/C++ empowerment
What is C?
Logistics
Functions
v o i d p r i n t s u m ( i n t arg1 , i n t a r g 2 ) {
i n t sum = a r g 1 + a r g 2 ;
/ P r i n t f i s a s p e c i a l f u n c t i o n t a k i n g v a r i a b l e
number o f a r g u m e n t s . /
/ The r e t u r n i s o p t i o n a l . /
return ;
}
/ Each e x e c u t a b l e n e e d s t o h a v e a main f u n c t i o n w i t h
t y p e i n t . /
i n t main ( ) {
p r i n t s u m (3 , 4) ;
return 0;
}
Goodbye
C/C++ empowerment
What is C?
Logistics
int x ;
int y , z ;
x = 1;
/ F u n c t i o n s can h a v e l o c a l v a r i a b l e s . /
void foo () {
int x ;
x = 2;
}
/ Arguments a r e l o c a l l y s c o p e d . /
void bar ( i n t x ) {
x = 3;
}
Goodbye
C/C++ empowerment
What is C?
Logistics
Conditionals
int foo ( int x ) {
/ C h a s t h e u s u a l b o o l e a n o p e r a t o r s . /
i f ( 3 == x ) {
return 0;
}
}
i n t bar () {
/ Note t h a t c o n d i t i o n s a r e i n t e g e r t y p e , where 1 i s
t r u e ! /
i f (1) {
return 0;
}
}
Goodbye
C/C++ empowerment
What is C?
Logistics
Loops
For loops
void foo () {
int i ;
f o r ( i = 1 ; i < 1 0 ; ++i ) {
p r i n t f ( %d\n , i ) ;
}
}
While loops
void bar () {
int lcv = 0;
while ( l c v < 10) {
p r i n t f ( %d\n , l c v ) ;
++l c v ;
}
}
Eunsuk Kang and Jean Yang
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Including headers
Header denitions allow us to use things dened elsewhere.
Header les (.h les) typically contain declarations
/ L i b r a r y f i l e . /
/ L o c a l f i l e . /
Goodbye
C/C++ empowerment
What is C?
Logistics
Until tomorrow. . .
Homework (due tomorrow)
Get a C compiler up and running.
Compile and run Hello world. Make a small extension to
Questions?
The course sta will be available after class.
Goodbye
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.