topskill.dev
CoursesTracks
All courses/C Programming for BeginnersFrom a C file to a running program
How Programs Work
3 / 7
← C Programming for Beginners
○What a program actually does○The computer and the operating system●From a C file to a running program○Compiled and interpreted programs○Trace One Tiny C Program○Print the Opening Sign✦Module Quiz
○Your First C Program○Variables and Formatted Output○Arithmetic and Integer Division○Formatting and Numeric Conversion○Calculate a Shop Total✦Module Quiz
○Declare and initialize variables○Label the parts bin○Assign a new value○Update the checkout board○Choose int, double, and char○Write a battery test label○Keep local names and constants clear○Count free kit slots✦Module Quiz
○Match printf placeholders and arguments○Print a radio test slip○Build lines with escapes and multiple calls○Print a clock pickup note○Print percent signs and aligned values○Line up a cleaning report○Evaluate expressions before printing○Divide reflectors among trays✦Module Quiz
○Comparisons and True or False○How if and else Choose a Path○Choose a Ticket Message○Select a Fixed Choice with switch○Choose a Service Desk✦Module Quiz
○For Loops: Repeat a Known Number of Times○Add Daily Contributions○While Loops: Repeat While a Condition Holds○Make a Countdown○Run Once with do while○Label a Two-Row Shelf○Label Tool Drawers✦Module Quiz
○Define and Call a Function○Follow a Function Call and Its Return Value○Return a Square○Declare Before a Function Call○Declare and Convert✦Module Quiz
○Arrays and Zero-Based Indexes○Add Array Elements○Count Array Slots Safely○Average Workshop Ratings○Rows and Columns in Memory○Total a Two-Row Grid✦Module Quiz
○C Strings and the Null Terminator○Count a Label○Compare Complete Strings○Verify a Pickup Code○Visit Each Character○Count a Letter in a Label✦Module Quiz
○Pointers: Addresses and Dereferencing○Update Through a Pointer○Pass an Address to a Function○Swap Two Counts○Array Addresses and Offsets○Total with an In-Bounds Pointer○Null, Validity, and Lifetime○Handle an Optional Pointer✦Module Quiz
○Pass an Array and Its Length○Total Readings in a Function○Change Array Elements Through a Parameter○Update Each Stock Count✦Module Quiz
○Define a Supply Record○Record Thread Supplies○Update a Record Member○Update the Paper Stock○Walk an Array of Records○Total the Flyer Stacks○Pass a Record to a Function○Print a Badge Record✦Module Quiz
○One Value in Shared Storage○Record One Ticket Value○A Tag Tells You What Is Stored○Read a Tagged Repair Ticket○Compare Union and Struct Storage○Choose the Right Storage✦Module Quiz
○Read Bits with AND○Check an Equipment Flag○Turn a Flag On with OR○Mark a Kit Ready○Toggle and Clear Individual Flags○Toggle a Warning Flag○Move a Bit into Position○Build a Position Mask✦Module Quiz
○Include the Right Header○Measure a Label with strlen○Guard a Macro Default○Set a Fallback Badge Limit○Include Code Only for Debug Builds○Show an Inventory Diagnostic When Enabled○Parenthesize a Simple Macro○Keep a Macro Calculation Grouped✦Module Quiz
○Name a Status with enum○Confirm an Application Status○Alias a Record Type with typedef○Initialize a Ribbon Record✦Module Quiz
○Where the storage comes from○Request and Release an Array○Store Three Repair Counts○Start Allocated Counters at Zero○Start Station Counters at Zero○Allocate and Release Records○Allocate the parts report✦Module Quiz
○Print a Formatted Label○Print the carving sign○Print Characters with putchar○Build a two-letter mark○Format into a Bounded Buffer○Prepare the shelf label○Write a Line to stdout with fputs○Post the ready notice○Input and Diagnostics in a Local Terminal✦Module Quiz
How Programs Work

From a C file to a running program

From source file to running program

You write C instructions as text in a source file, usually with a .c ending. The file main.c is source code, not yet a runnable program. A build translates it into a form the execution environment can run.

Follow one build

  1. The preprocessor handles instructions such as #include, which brings in information from a header file.
  2. The compiler checks C syntax and translates the program. Assembly is a low-level notation for instructions; an assembler turns it into object code, instructions that still need to be connected with other program code. Tools often hide these separate steps behind one command.
  3. The linker connects object code with the other code it needs, including library functions. The result is an executable. Some library connections may be completed when the program loads.
  4. Running that executable starts the program. Its instructions can now produce output.

A library provides reusable code for programs to call. We'll use printf from the C standard library to print text. The header tells the compiler how to call it; linking connects the program to the code that does the printing.

Building is different from running

On a computer with GCC installed, this terminal command builds a file:

text
gcc -std=c11 -Wall -Wextra main.c -o main

gcc names the tool. -std=c11 selects the C version used in this course; -Wall -Wextra request useful warnings. main.c is the input file, and -o main names the executable. On a Unix-like system, ./main runs it. Windows uses the resulting executable's name. These local commands are optional; the lesson Run controls handle execution on the site.

If you change the source, build again. Running an old executable still runs the old instructions.

A missing semicolon can stop a build with a compiler diagnostic: a message explaining a problem in the source. A program that builds but prints the wrong donation total has a logic error. The code is valid enough to run, but it does the wrong work. Read the first diagnostic first; one mistake can cause several later messages.