Understanding Programming Fundamentals | Programming in C

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

Next lesson: Core Program Structure: Input, Processing, and Output →

Earn 3 college credits for Programming in CRecommended for credit by NCCRS · Computer Science 240 · self-paced · one payment, lifetime access

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.

Compare: C vs C++

Why take it here

Why students take Programming in C with UPI Study

How programs work close to the machineProgramming in C teaches how a program uses memory: variables and data types, control flow, functions, arrays and strings, pointers, files, structures and dynamic memory. C is the base for operating systems, embedded devices and many computer-science courses.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
Source code is the human-readable text a programmer writes, while machine code is the binary instructions a processor actually runs. C source code is plain text saved in a file ending in .c. A compiler translates it into machine code, which depends on the specific chip. Writing machine code by hand would be slow and error-prone, so programmers use a language with strict rules instead.
What is the difference between a compiled language and an interpreted language?
A compiled language is translated into machine code once, before the program runs, while an interpreted language is translated as it runs. A C compiler turns the whole source file into an executable that the computer runs directly. Python is usually run by an interpreter, which has to be present every time the program runs. Translating ahead of time is one reason C programs are fast.
Why does a C program still show old output after the source code is edited?
The program shows old output because the executable was not rebuilt after the edit. An executable is a separate file made from the source code at compile time, and it does not change until the compiler runs again. The fix is a three-step habit: save the file, compile it, then run it. Skipping the compile step means running the previous version of the program.
Can a compiled C program run if its source file is deleted?
Yes, a compiled executable runs on its own without the source file. The source file is needed only for translating, and that work is finished once the compiler has produced the executable. Losing the source still causes trouble later, though, because without it the program cannot be changed and rebuilt. Keeping source files safe and backed up is a basic programming habit.

About the Programming in C course

How many college credits is Programming in C?
Programming in C (Computer Science 240) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Programming in C cost and what is included?
$250, paid once, with lifetime access: all 78 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Programming in C take?
It is self-paced with no deadlines. The 78 lessons total about 9 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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.

Programming in C
3 credits · NCCRS
Enroll →