The C programming language
- The (close) relationship between C source
asm.c and
corresponding assembly language
asm.s.
Note the shift to implement a division by 2.
asm.s is obtained by: gcc -S asm.c
.
- The complexity of the compiler.
Finding out the number of significant digits in a float
(on this particular hardware/OS platform):
digits.c.
Compiled with gcc -v digits.c
gives
output.
This shows the include file path searched for float.h.
- The size of (objects of) different types
(on this particular hardware/OS platform):
sizeof.c
and its
output.
sizeof may be used with both object and type arguments.
- A simple template for C files:
template.c.
- Be verbose rather than obscure (re-use and maintainability is our aim) !
verbose.c.
Characters in C
Arrays in C
- Simple array example: calculate average:
array.c and its
output
- Strings in C: strcp, strcat, strlen:
str.c and its
output
- Strings in C: strcat:
full.c and its
output
- Strings in C: strcmp:
strcmp.c and its
output.
Comparison is lexicographic. strcmp() returns 0 in case of equality.
Beware when used as a condition (in if etc.).
- Reading Strings in C: fgets(name, sizeof(name), stdin)
- Multidimensional arrays in C
- Reading different types: fgets() followed by sscanf()
Decision and Control Statements
The C Preprocessor
Variable Scope and Class AND modular programming
Bit operations
struct, union, and typedef
- The polymorph example
demonstrates the use of struct and union types to build
a polymorphic vector. The example
input/output demonstrates the program. Read all the files very
carefully as they contain many previously introduced techniques !
C pointers
- call.c
and its output
demonstrate how a pointer may be used to pass a parameter
to a function "by reference".
- pointer-use.c
and its output
demonstrate the combination of pointer de-referencing and
auto-increment.
- array-p.c
and its output
demonstrate how array addressing and pointer arithmetic
are similar.
init-a.c
demonstrates this too. Stepping through this with the gdb
(or xxgdb) debugger shows how pointer arithmetic takes the type
(and hence the size) of what is pointed to in account.
- Initializing and array with
array indexing or
with pointer arithmetic
- Command line arguments access:
- Cloning of structures in an object-oriented fashion
(emulating class methods by means of function pointers):
initstruct.c.
Interesting, but not to study for the final exam.
- Building a tree of words:
words.
words.c is the example from the
book.
indentwords.c
prints the indented tree.
lispwords.c prints
the tree in a lisp-like syntax. This is easy to read in again.
The words.worst.txt is an example input file which leads to
a degenerate tree (a list).