UPI Study › Courses › Programming in C › Free lessons › Lesson 1.1 Free with a free account
Understanding Programming Fundamentals
Programming in C · Chapter 1: Programming Fundamentals, Pseudocode, and Program DevelopmentSection 1.1 · lesson 1 of 788 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Programming in C.
Lesson complete
Earn the 3 college credits for Programming in C
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Core Program Structure: Input, Processing, and Output →Next lesson: Core Program Structure: Input, Processing, and Output →
In this lesson
How exact instructions become machine code through a C compiler.
- Define a program, code and an instruction, and explain why every step must be spelled out
- Describe how C source code becomes machine code and an executable
- Compare compiled and interpreted languages
- Explain why C is fast, close to the machine and small
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,146 words). Read along, or search it.
Opening Question
From Insert Token to Player One
You drop a token into a game machine, and the screen flips from INSERT TOKEN to PLAYER ONE. Nobody inside the machine made that choice. Long before you arrived, someone wrote the exact instructions it follows. So how does a person's idea become something a chip can actually run? And why is C so good at that job?
The Problem
Computers Have No Common Sense
Meet Starlight Arcade, a small arcade full of game machines, tokens and high scores. Priya builds its software, and Sam tests it, and finds the bugs. Their first job is the token changer, the machine that swaps a player's dollars for game tokens. Priya's first idea is one sentence: give the player tokens. A person at the counter would understand that right away. A computer would not. How many tokens? For how much money? What should it do first? A computer is very fast, but it has no common sense. It does exactly what it's told, in exactly that order, and nothing else.
Definition
A Program Is a List of Exact Steps
So every step has to be spelled out. Wait until a bill goes into the slot. Read the bill's value in dollars. Multiply the dollars by four. Drop that many tokens into the tray. Show, enjoy your tokens, on the screen. That list is the heart of programming. A program is a set of exact instructions that tells a computer what to do, step by step. Writing those instructions is programming, or coding. The instructions themselves are code, and each single step is one instruction.
Missing Step
The Torn Bill Nobody Planned For
Sam read the plan and asked one question: what does it do if someone puts in a torn bill? Priya had no answer, because her plan never said. The computer won't invent one. Most bugs start right here, as a step nobody wrote down.
Machine Code
From an Idea to Zeros and Ones
Here's a surprise. The chip inside a computer, the processor, doesn't understand English. It doesn't understand C either. It understands only machine code: long patterns of zeros and ones, each switching tiny circuits on or off. Writing a whole game in zeros and ones would take forever, and one wrong digit would be nearly impossible to find. So people write in a programming language: real words and symbols, with strict rules, so every line means exactly one thing. Your idea takes a trip down three steps. First the idea, in English. Then source code, in C, which you write. Then machine code, which a tool produces for you. These zeros and ones are only an illustration; real machine code depends on the chip.
Source Code
High Level Yet Close to the Machine
The code a person writes is called source code. For C, it's plain text, saved in a file whose name ends in dot c. Languages that read closer to human words are called high-level languages. Machine code is the lowest level of all. C is high-level enough to read, yet it stays unusually close to the machine. That's a big part of why people choose it.
Compiling vs Interpreting
Translate Once or Every Time
There are two main ways to get from source code to a running program. Picture a book written in Japanese that you want to read in English. You could hire a translator to turn the whole book into English once, then read that copy as often as you like. Or someone could sit beside you and translate aloud, sentence by sentence, every single time you read it. C works like the first translator. A compiler translates your whole source file into machine code before the program runs. It saves the result as an executable: a file the computer can run directly. A language used this way is a compiled language. The second way is interpreting. Python, for example, is usually run by an interpreter that must be there on every run.
Worked Example
Compiling and Running Hello Arcade
Here's a complete C program for the arcade's welcome screen. Three printf lines, each one instruction: show this text. Two free compilers are everywhere: GCC and Clang. They take the same commands and options; in these videos you'll watch Clang. The first command compiles. Dash o picks the name of the executable, and dash W all turns on the common warnings. It printed nothing at all, and for a compiler, silence is good news. It means no problems found. The second command, dot slash hello arcade, runs that program in this folder. Three instructions went in, and three lines came out, in the same order.
Common Mistake
Running Yesterday's Program
Now a common mistake. Priya changes player one to player two in the source file, runs dot slash hello arcade again, and still sees player one. She hadn't compiled again. The executable is a separate file, made from the old source code, and it doesn't change until the compiler runs again. So in C, every edit means three steps: save, compile, then run. Skip the middle one, and you are running yesterday's program.
Quick Check
The Executable Runs Without Its Source
Quick check. Sam changes the last line to say, good luck, player two. He saves, and compiles. Then, by accident, he deletes hello arcade dot c. Only the executable is left. He types dot slash hello arcade. Does it print player two, print player one, or fail because the source file is gone? Pause, and decide. It prints player two. He compiled after the edit, so the executable already holds the new message. And an executable runs on its own. The source file was only needed for translating, and the translating is done. Player one would need a skipped compile. Losing the source hurts later, though: without it, he can't change the program again.
Why Learn C
Fast, Close to the Machine and Small
So why learn C, out of hundreds of languages? It came out of Bell Labs in the early nineteen seventies, and it's still in heavy use. First, it's fast. It's compiled straight into machine code, so no translator works while the program runs. Second, it's close to the machine. C lets you work with memory directly, down to the exact spot where a value is stored. Third, it's small. A C program can run on a tiny chip with very little memory, like the one in a microwave or a thermostat.
Where C Runs
C Trusts You, So Ask for Warnings
Most of the time it works out of sight. Most of the Linux kernel is C, and the usual Python interpreter, CPython, is itself a C program. All that power comes with a trade: C trusts you. It checks your grammar, but lets you do risky things, so always ask for warnings.
Key Takeaways
Instructions, Compilers and Recompiling
To sum up. A program is a list of exact instructions, because a computer has no common sense. You write source code; a compiler turns it into machine code, once, and saves an executable. Change the code, and you must compile again before running. And C is fast, close to the machine, and small enough for tiny chips.
Think About It
Finding the Gap in Three Steps
Something to think about. Pick a machine at home, a washing machine or a TV remote, and write three exact steps for one button. Then hunt for the gap. What should happen if the button is pressed twice, or with the door open?
About Programming in C at UPI Study
Programming in C (Computer Science 240) is a self-paced online course of 78 video lessons in 11 chapters, from pseudocode and your first program to data types, decisions, loops, functions, arrays, strings, pointers, files, structures, dynamic memory and linked lists. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: C vs C++
Why take it here
Why students take Programming in C with UPI Study
Where the credit goes
Universities that work with NCCRS
Programming in C carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Understanding Programming Fundamentals
What is the difference between source code and machine code?
What is the difference between a compiled language and an interpreted language?
Why does a C program still show old output after the source code is edited?
Can a compiled C program run if its source file is deleted?
About the Programming in C course
How many college credits is Programming in C?
How much does Programming in C cost and what is included?
Which universities accept UPI Study credits?
How long does Programming in C take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Programming in C.
78 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
3 credits · NCCRSEnroll →