Programming Open textbook

C programming basics: where C came from, how a program is built, printf and variables

Built automatically from the first chapters of the open textbook "C programming" on Wikibooks: why C, its history, the first program and how it is built, printf, variables and scanf. Not reviewed by a person.

3 lessons, 21 steps

Get it on Google Play

A first look at C, one question at a time

This course is a first look at C for people who have not written it before. It follows the opening chapters of the open textbook "C programming" on Wikibooks, from why C is worth learning to reading what the user types. Most steps ask what the book says or what a short snippet does; no step asks you to write a program.

Lesson 1 has no code. It covers why the book prefers C to assembly, including portability, the line of languages from Fortran to B that led to C, how versions of the C standard are named, and what a beginner needs to start: a text editor, a compiler and the command line. Lesson 2 goes through the book's hello program and the stages that build it: the preprocessor, the syntax check, the object file and linking. You meet header files such as stdio.h, the exit status that main returns, the two forms of comments and how many values an 8-bit char can hold. Lesson 3 covers printf with a field width, variable names, block scope, static and const variables, and why scanf needs &a rather than a.

Each lesson has a one-minute introduction and seven steps. You pick an option, put items in order, or type a word or a number. When your answer is wrong, the AI tutor asks a question about it, then gives a hint, then a partial step, and Show solution is always there. A four-question quiz before and after each lesson shows what changed.

Know where the material comes from. The course was built automatically from the open textbook "C programming" on Wikibooks, and no person has reviewed it. The book is written by volunteers and may contain errors, and the three lessons cover only its first chapters.

What the lessons cover

  • Explain why the book prefers C to assembly and put the languages that led to C in order
  • Order the stages that build a C program, from the preprocessor to linking
  • Predict what printf prints with a field width and which variable a name refers to after a block
  • Say what static and const do to a variable and why scanf needs the address of a variable

Lessons

  1. Why C, and Where It Came From

    7 steps, 1 min intro

  2. Your First C Program and How It Is Built

    7 steps, 1 min intro

  3. Output, Variables and Input

    7 steps, 1 min intro

Reading a printf field width

Tutor: The width in a format specifier is the minimum number of characters a value takes up. The call printf("[%6d]", 42); prints 42 between square brackets. How many spaces come between [ and 42?

You: 6

Tutor: Does the width count the digits of the number as well?

You: Yes. 42 takes 2 of the 6 characters, so there are 4 spaces.

Tutor: Right, 4. The number is right-aligned and the spaces fill the rest of the width.

Based on a real step from lesson 3. The tutor's wording varies, and AI can be wrong: the tutor answers from the course material and labels a reply it could not check.

Who this C warm-up fits

  • You want a first taste of C before a programming class or a course that uses it.
  • You know a little Python or JavaScript and want to see how a C program is compiled and linked.
  • You want to know why C is worth learning and where it came from.
  • You are fine with a short, automatically built practice set instead of a full C course.

About this C programming course

Do I write and compile C code in the app?

No. You read short snippets and answer questions about them: pick an option, type a word such as variadic, or enter the number a line of code prints. If you want to compile the snippets yourself, lesson 1 covers what the book says you need: a text editor and a compiler.

Does the course cover pointers, arrays or loops?

No. The three lessons stop at printf, variables and scanf. Lesson 3 explains that & gives scanf the address of a variable, but pointers, arrays and loops are not covered.

Who checked the questions?

Nobody. The lessons were generated automatically from the open textbook and were not reviewed by a person. The sources and their CC BY-SA 4.0 license are listed below, so you can compare any step with the original chapter.

Is the course free?

One lesson in Ai Teacher is free. After that, a subscription opens all lessons. You can pay monthly or yearly in Google Play, and usage limits apply.

Source and license

This course is adapted from C programming, an open textbook on Wikibooks written by Wikibooks contributors (see the page history of each chapter below). The textbook is licensed under CC BY-SA 4.0.

This course was built automatically from the open textbook "C programming" on Wikibooks. No person has reviewed it. Changes: Adapted by AI into lessons and questions; shortened. Written by volunteers; it may contain errors.

Chapters used

  1. Why learn C? revision 4652566, authors
  2. History revision 4652570, authors
  3. What you need before you can learn revision 4652574, authors
  4. Intro exercise revision 4652583, authors
  5. Preliminaries revision 4672498, authors
  6. Basics of compilation revision 4652558, authors
  7. Simple output revision 4658932, authors
  8. Variables revision 4671995, authors
  9. Simple input revision 4652595, authors

Start C programming in Ai Teacher

One lesson in the app is free. Ai Teacher is available for Android on Google Play.

Get it on Google Play