Our reference
- Chapters 7 to 14 of An Introduction to the C Programming Language and Software Design
But let’s start with some Fall 2015 CSCI 255 notes on C vs Java.
Chapter 7 — Pointers
- Draw elements of the following types
int *char *int **void *
- Two new operators
- unary
&— address-of - unary
*— dererence - study examples on page 50
- unary
- Examples of assigned to pointers and pointers to pointers
- The
constdeclaration modifiesconst int* pA ;int const* pB ;
- call by reference (vs call by value)
- Write an integer swap routine
- C++ reference
strtolman page — this is hard
- arrays are constant pointers
- the mysteries of pointer arithemetic
- passing a function with pointers
- Spring 2017 CSCI 255 notes
- Problem 15 of Spring 2017 CSCI 255 final
- Fall 2011 ECE 209 notes
Chapter 8 — Arrays and Strings
- Size of array is usually set in declaration
- until you get to Chapter 9
- What a hack to find the size —
sizeof(P)/sizeof(*P) - Strings are null terminated
chararrays - C string library
- arrays of pointers
- multidimensional array
Chapter 9 — Dynamic Memory
Concentrate on sections 9.1—9.3: We are skipping the CSCI 202 stuff.
- Memory regions of C
mallocand friends- There is no garbage collection in C: use
free
Chapter 10 — The C Preprocessor
- Fall 2009 ECE 209 C Preprocessor notes
- Try: gcc -E pointers.c > pointers.c-after-cpp
Chapter 11 — Structures and Unions
- A C
structis a Javaclasswith onlypublicfields — no methods - A C
unionis strange, but useful- /usr/include/netinet/ip.h vs IP4 header
- /usr/include/netinet/ip_icmp.h vs ICMP header
- Fall 2011 ECE 209 structure notes (with linked lists)
- Fall 2011 ECE 209 union examples
Chapter 12 — Bitwise Operators
We did much of this in Chapter 2 of the textbook.
- Bitwise operators: Just like Java except there is no
>>>- C’s
signed >>is like Java’s>> - C’s
unssigned >>is like Java’s>>>
- C’s
- Bitwise logical operators have a lower precedence than relational
operators:
x & b == cisx & (b == c) - Bit-fields are used in the IP and ICMP headers
Chapter 13 — Input and Output
- %[flags][width][.precision][length]specifier
- The C/C++
printfis a bit like the Javaformat
- The C/C++
- %[*][width][length]specifier
- The C/C++
scanfis very different from the JavaScanner - C input uses pointers
- The C/C++
- In practice C++ I/O, with its heavy use of operator overloading and multiple inheritance, does not look at all like C and Java I/O
- File control:
fopenandfclose - Stream access
- Random access:
fseekandftell - Command line arguments
- Fall 2010 ECE 209 formatting notes
Chapter 14 — Generic Programming
This is not a strong point of C!
typedef: frequently used by experienced programmers- macros: be very careful
union: be very carefulvoid *: the generic pointerqsort(): learn how to use it