Professional Documents
Culture Documents
MIT6 088IAP10 Lec01
MIT6 088IAP10 Lec01
What is C?
Logistics
Goodbye
MIT CSAIL
C/C++ empowerment
What is C?
Logistics
Goodbye
Eunsuk Kang and Jean Yang The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
Eunsuk Kang and Jean Yang The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
Lecture plan
C/C++ empowerment
What is C?
Logistics
Goodbye
Images of Wonder Woman and circuit boards removed due to copyright restrictions.
Course goal: to help procient programmers understand how and when to use C and C++.
Eunsuk Kang and Jean Yang The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
Background check
Expected knowledge
Basic data structures (linked lists, binary search trees, etc.)? Familiarity with basic imperative programming concepts.
Variables (scoping, global/local). Loops. Functions and function abstraction.
Other knowledge
Functional programming? Systems programming? Hardware? OOP with another language?
Eunsuk Kang and Jean Yang The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
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
C/C++ empowerment
What is C?
Logistics
Goodbye
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;
C/C++ empowerment
What is C?
Logistics
Goodbye
Recommended references
Books
Kernighan, Brian, and Dennis Ritchie. The C Programming Language. Upper Saddle River, NJ: Prentice Hall, 1988. ISBN: 9780131103627. Roberts, Eric. The Art and Science of C. Reading, MA: Addison-Wesley, 1994. ISBN: 9780201543223.
Online resources
http://www.cprogramming.com
Eunsuk Kang and Jean Yang The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
The C family
C
Developed in 1972 by Dennis Ritchie at Bell Labs.
Imperative systems language.
C++
Developed in 1979 by Bjarne Stroustrup at Bell Labs. Imperative, object-oriented language with generics.
C/C++ empowerment
What is C?
Logistics
Goodbye
Vocabulary check
C/C++ empowerment
What is C?
Logistics
Goodbye
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.).
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
Controller
Control/Status
ALU
IR
PC
I/O
Registers
Memory
Eunsuk Kang and Jean Yang The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
array.
Access heap using special
pointer syntax.
The whole program has
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
Goodbye
the stack.
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
Eunsuk Kang and Jean Yang The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
Using C
i n t main ( ) {
p r i n t f ( Hello world ! ) ;
}
C/C++ empowerment
What is C?
Logistics
Goodbye
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 . /
p r i n t f ( The sum i s %d \ n , sum ) ;
/ 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; }
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
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; } }
C/C++ empowerment
What is C?
Logistics
Goodbye
Loops
For loops
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 The Adventures of Malloc and New
C/C++ empowerment
What is C?
Logistics
Goodbye
C/C++ empowerment
What is C?
Logistics
Goodbye
Including headers
Header denitions allow us to use things dened elsewhere.
Header les (.h les) typically contain declarations
(variables, types, functions). Declarations tell the compiler these functions are dened somewhere.
Function denitions typically go in .c les. Angle brackets indicate library header les; quotes indicate
C/C++ empowerment
What is C?
Logistics
Goodbye
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.
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.