Programming is a foundational discipline within computer science. It combines elements of mathematics, engineering, and natural science to design, implement, and analyze computational systems. Learning to program is not only about mastering syntax, but also about developing a structured way of thinking—breaking problems into components, reasoning formally, and evaluating trade-offs in design decisions.
The C programming language remains a central tool in computing education due to its efficiency, explicit memory model, and close relationship to system-level concepts. Studying C provides a strong understanding of how programs interact with hardware and how core programming constructs are implemented.
About the book
How to Think Like a Computer Scientist – C Version by Thomas Scheffler, based on previous work by Allen B. Downey, introduces programming through the C language while emphasizing computational thinking.
The book is designed as an instructional text for beginners. It starts with fundamental questions—what a programming language is, what a program is, and what debugging means—and progressively builds toward more advanced topics such as recursion, arrays, strings, pointers, and structures.
The material assumes no advanced prior experience in programming. It is suitable for students beginning computer science studies, self-learners seeking a structured introduction to C, and technical readers who want to strengthen their understanding of foundational programming concepts.
The text is released under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
What you will learn
Readers of this book will develop both conceptual and practical skills in programming with C. The progression of topics supports gradual mastery of core principles, including:
- Understanding programming languages, programs, and debugging techniques
- Working with variables, types, operators, and expressions
- Designing and implementing functions with parameters and return values
- Applying conditionals and recursion to solve problems
- Using iteration constructs such as
whileandforloops - Manipulating arrays and performing simple statistical operations
- Handling strings, characters, pointers, and user input
- Working with structures, compound data types, and parameter passing mechanisms
- Applying coding style principles and conventions
Beyond syntax, the book emphasizes problem decomposition, formal reasoning, modular design, encapsulation, and generalization—skills central to thinking like a computer scientist.
Table of contents
- 1 The way of the program
- 1.1 What is a programming language?
- 1.2 What is a program?
- 1.3 What is debugging?
- 1.3.1 Compile-time errors
- 1.3.2 Run-time errors
- 1.3.3 Logic errors and semantics
- 1.3.4 Experimental debugging
- 1.4 Formal and natural languages
- 1.5 The first program
- 1.6 Glossary
- 1.7 Exercises
- 2 Variables and types
- 2.1 More output
- 2.2 Values
- 2.3 Variables
- 2.4 Assignment
- 2.5 Outputting variables
- 2.6 Keywords
- 2.7 Operators
- 2.8 Order of operations
- 2.9 Operators for characters
- 2.10 Composition
- 2.11 Glossary
- 2.12 Exercises
- 3 Function
- 3.1 Floating-point
- 3.2 Constants
- 3.3 Converting from double to int
- 3.4 Math functions
- 3.5 Composition
- 3.6 Adding new functions
- 3.7 Definitions and uses
- 3.8 Programs with multiple functions
- 3.9 Parameters and arguments
- 3.10 Parameters and variables are local
- 3.11 Functions with multiple parameters
- 3.12 Functions with results
- 3.13 Glossary
- 3.14 Exercises
- 4 Conditionals and recursion
- 4.1 Conditional execution
- 4.2 The modulus operator
- 4.3 Alternative execution
- 4.4 Chained conditionals
- 4.5 Nested conditionals
- 4.6 The return statement
- 4.7 Recursion
- 4.8 Infinite recursion
- 4.9 Stack diagrams for recursive functions
- 4.10 Glossary
- 4.11 Exercises
- 5 Fruitful functions
- 5.1 Return values
- 5.2 Program development
- 5.3 Composition
- 5.4 Boolean values
- 5.5 Boolean variables
- 5.6 Logical operators
- 5.7 Bool functions
- 5.8 Returning from main()
- 5.9 Glossary
- 5.10 Exercises
- 6 Iteration
- 6.1 Multiple assignment
- 6.2 Iteration
- 6.3 The while statement
- 6.4 Tables
- 6.5 Two-dimensional tables
- 6.6 Encapsulation and generalization
- 6.7 Functions
- 6.8 More encapsulation
- 6.9 Local variables
- 6.10 More generalization
- 6.11 Glossary
- 6.12 Exercises
- 7 Arrays
- 7.1 Increment and decrement operators
- 7.2 Accessing elements
- 7.3 Copying arrays
- 7.4 for loops
- 7.5 Array length
- 7.6 Random numbers
- 7.7 Statistics
- 7.8 Array of random numbers
- 7.9 Passing an array to a function
- 7.10 Counting
- 7.11 Checking the other values
- 7.12 A histogram
- 7.13 A single-pass solution
- 7.14 Random seeds
- 7.15 Glossary
- 7.16 Exercises
- 8 Strings and things
- 8.1 Containers for strings
- 8.2 String variables
- 8.3 Extracting characters from a string
- 8.4 Length
- 8.5 Traversal
- 8.6 Finding a character in a string
- 8.7 Pointers and Addresses
- 8.8 String concatenation
- 8.9 Assigning new values to string variables
- 8.10 strings are not comparable
- 8.11 Character classification
- 8.12 Getting user input
- 8.13 Glossary
- 8.14 Exercises
- 9 Structures
- 9.1 Compound values
- 9.2 Point objects
- 9.3 Accessing member variables
- 9.4 Operations on structures
- 9.5 Structures as parameters
- 9.6 Call by value
- 9.7 Call by reference
- 9.8 Rectangles
- 9.9 Structures as return types
- 9.10 Passing other types by reference
- 9.11 Glossary
- 9.12 Exercises
- A Coding Style
- A.1 A short guide on style
- A.2 Naming conventions and capitalization rules
- A.3 Bracing style
- A.4 Layout
- B ASCII-Table
Book details
- Title: How to Think Like a Computer Scientist – C Version
- Author(s): Thomas Scheffler; based on previous work by Allen B. Downey
- Main category: Programming
- Subcategory: C
- Language: English
- License: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
More books in: C, Programming
Legal notice: This book is shared for educational purposes only. The content is distributed under Creative Commons licenses or with explicit permission from the author. FreeProgrammingBooks may host files that comply with their respective licenses.