Notes and Talks/UJEP/UPC

Introduction to Programming in C

Course objectives

The course teaches the basics of C in the K&R spirit, using a modern dialect of the language. Most work is done in a Linux or WSL terminal (bash). Emphasis is placed on understanding the fundamentals of the language, low-level programming principles, memory management, native data types, and code efficiency.

Requirements for students

Students are expected to participate actively in seminars, complete assignments continuously, and complete a programming project that shall be assigned no later than week 8.

Content

1Introduction to C and program structureHistory of C, its philosophy and use. Working in the terminal. First program "Hello World", compilation and execution.
2Number types and operationsRepresentation of numbers, overflow.
3Program flow controlConditions, switches, loops, signals, command-line arguments.
4Functions, pointers, arrays, stringsDefining, declaring, and calling functions. Parameters and return values. Scope of variables. Recursion. Modular program structure. The preprocessor, header files, and conditional compilation. An introduction to the standard C library.
5Pointers, arrays, stringsOne-dimensional arrays. Relationship between arrays and pointers. Pointer arithmetic. Pointers as function arguments (output parameters). Strings as character arrays. Standard functions for working with strings.
6Multidimensional arrays, pointers to functionsArrays of pointers versus multidimensional arrays. Pointers to functions as a tool for abstraction. Command-line arguments.
7Input and outputThe standard library header stdio.h. Standard streams (stdin, stdout, stderr). Formatted input and output. Working with files. Chaining input and output using pipes and redirection.
8Data structures and memory managementComposite data types. Structure definitions, nested structures, and arrays of structures. Static and dynamic memory allocation. Data lifecycle. Common memory errors (memory leaks, use-after-free errors, and illegal access).
9Terminal interface using ncursesA library for controlling the terminal: windows, keyboard input, and full-screen output.
10The C standard libraryThe headers stdlib.h, string.h, ctype.h, math.h, time.h. Quick sort. Handling errors from library calls.
11Calling C from other languagesWriting a Python library in C. Integrating C and C++ code.
12-13Presentations of student projects

Literature