Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 1: Introduction

1.1 Welcome

Welcome to “Programming for All: C Edition for Python Programmers”. This book helps you, a Python programmer, make the move to C. Along the way you’ll find comparisons between the two languages, practical examples, and detailed explanations of the core concepts.

1.2 Why learn C?

C is an efficient system programming language, and it has influenced many modern languages, Python among them. Learning C gives you a clearer picture of how computers work.

Benefits of learning C
  1. Performance: C programs are often faster and more efficient than programs written in interpreted languages like Python.
  2. Low-level access: you can work directly with hardware and memory, which gives you more control over system resources.
  3. Foundation for other languages: many languages, such as C++ and Java, are based on or influenced by C, so knowing C makes them easier to learn.
  4. Industry relevance: C is widely used in system programming, embedded systems, and high-performance applications.

1.3 History of C

Dennis Ritchie developed C at Bell Labs in the early 1970s. He designed it as a small, efficient language for writing operating systems, and it soon became the usual choice for system programming. The UNIX operating system, first written in assembly language, was rewritten in C, and this contributed a great deal to its success.

Milestones:

  • 1972: Dennis Ritchie develops C at Bell Labs.
  • 1978: Brian Kernighan and Dennis Ritchie publish “The C Programming Language”, the source of the name K&R C.
  • 1989: The ANSI C standard (ANSI X3.159-1989) is established.
  • 1999: The C99 standard adds features such as inline functions, variable-length arrays, and improved support for IEEE floating-point arithmetic.
  • 2011: The C11 standard adds features like multi-threading and atomic operations.

1.4 How to use this book

The book introduces C gradually and draws on what you already know about Python. Each chapter builds on the one before, starting with the fundamentals and moving on to advanced topics and practical applications.

The rest of the book is laid out like this:

  • Chapter 2, Building a Simple Program, shows how to write and compile a C program and how a compiler differs from an interpreter.
  • Chapter 3, Core Concepts, covers data types, variables, operators, control structures, and functions, comparing each with Python.
  • Chapter 4, Advanced Topics, moves on to pointers, memory management, structs, enums, and file I/O.
  • Chapter 5, C Libraries, explains how to use standard library functions, write header files, and work with linkers and makefiles.
  • Chapter 6, Comparison of Python and C, sets out the main differences between the languages and the common pitfalls when you move from Python to C.
  • Chapter 7, Practical Applications, puts your C knowledge to work on a simple game, a small web server, and system utilities.
  • The appendices hold reference sheets, further reading, and a glossary of terms.

Each chapter has hands-on examples to help you understand and apply the concepts, along with sections that compare Python and C syntax and behavior to make the move between them smoother. The appendices list further reading for when you want to go deeper.