First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

Course CL101 Introduction to C Programming (5 days)

Overview and Intended Delegates

Attendees are expected to have some programming experience in a procedural language such as Basic, Fortran or Pascal. The course is also suitable for recent engineering and computer science graduates who need to "cure" any bad (programming) habits they might have picked up at University. Drive and determination are important pre-requisites as the course aims to produce competent working programmers, as is a good sense of humour (vital when working under pressure). Good programmers think hard, but also have a strong obsessive streak .... a need to get a program fully debugged and working at all costs.

This is an intensive introduction to ANSI C programming using the GNU C compiler. At the end of the course attendees should be reasonably confident in reading and writing C programs and have a good practical understanding of advanced topics such as the use of C pointers , the relationship between pointers and arrays, as well as dynamic memory allocation and memory management. In addition, they will be able to understand makefiles and version control using SVN and Git.

Throughout, the course will emphasise a disciplined and structured approach to C programming. Debugging and code testing techniques will also be covered extensively, including the use of the GNU debugging tools. The course is not based on any particular Integrated Development Environment (IDE), and adopts a more traditional approach where files are created using a suitable text editor (such as Vi or EMACS or gEdit) and programs are compiled either by issuing commands at the commandline, or by invoking make on an appropriate makefile.

Course Content

  • Introduction to C
    • Brief history of C
    • Introduction to compiling and compilers and GNU C compiler
    • The basic anatomy of a C program
  • Data types, operators and expressions (the basics)
    • Base data types and their sizes
    • Constants and declarations
    • Variable names
    • Arithemetic operators
    • Relational and logical operators
    • Increment and decrement operators
    • Assignment operators
    • Expressions
    • Operator precedence
    • Casting and type conversion
  • Program flow control
    • if/else
    • switch
    • while , do-while and for-loops
    • statements and blocks
  • Functions
    • Functions and function prototypes
    • Returning values from functions
    • External variables and scope rules
    • Static variables
    • Call by value and recursion
  • Pointers and arrays
    • Pointers and addresses
    • Pointers as arguments to functions
    • Arrays
    • The relationship of pointers to arrays
    • Pointer arithmetic
    • How C deals with multi-dimensional arrays
    • Arrays of pointers: their uses and initialisation
    • Strings and string functions
  • Structures
    • Fundamentals of structures
    • Passing structures as arguments to functions
    • Returning structures as return values from functions
    • Arrays of structures
    • Pointers to structures
    • Using pointers to structures to pass values to a function and return values from a function
    • typedef and its uses in developing well structured and maintainable code
  • An introduction to algorithms and their associated data structures
    • Sorting arrays of records
    • Allocating and freeing memory (malloc and free)
    • Linked lists and queues
    • Indexing (table lookup, binary trees, hashing)
  • Input-output
    • Standard input and standard output
    • Formatted output: printf
    • Formatted input: scanf
    • The dangers of scanf
    • File access and file I/O
    • An overview of input-output in a windowing environment
  • Further topics
    • The MACRO pre-processor and how to use it wisely
    • Unions
    • Bit fields
    • Date and Time functions in the C Standard Library
    • Diagnostics- the assert macro
  • Makefiles, Libraries, SVN and Git
    • Simple make files
    • MACROS in make files
    • Use of dummy targets
    • Recursive makefiles
    • Building and using libraries
    • The importance of version control
    • Essentials of version control - introduction to SVN and Git