return;

Getting started with C programming - About -

This guide will teach you to make a C program within minutes, and gives you sample programs to mess around with. This isn't a "C tutorial" per se, the aim is to get you started, and show that making a C program isn't as hard as it may seem. To actually learn C, you should look for a C tutorial elsewhere.

There will be red outlined words later, click or hover over them to see additional explanation about things.


Crash course to programs

How to make a program?

To make a program, you need to give code to a compiler. The compiler reads your code, and creates a program based on it.

What actually IS the compiler? What is a program?

Everything that does something in your computer is a program, including the compiler. A compiler takes your code files, reads the text in them, and writes out a new file that has CPU instructions that tell the CPU do the same things as your code says. You could think of the compiler as a translator from one language to another; from a programming language into CPU language.

A program (also known as an "application" or "app") is any file that has a bunch valid CPU instructions in it. Programs can also use some functionalities from dynamic libraries (.dll files on Windows), and thus will fail to run if the library file is missing.

Your program file also has some information for your OS, for example to inform the OS where to find certain things from the file. You can search for the specifications to your operating system's executables (.exe on Windows) to find out what else is in the program file, but that isn't useful for programming unless you want to make a compiler or modify executables or practice hacking or something.

CPUs and instructions

A CPU instruction is a couple bytes of data (see 'What is data?' below). When you load those bytes into the CPU (your operating system does the loading), the CPU does something based on what the instruction says, like multiplying 2 numbers together, or moving to another position and reading the instructions from there.

An instruction set is a set of rules that define which bits represent which actions in the CPU, x86 is the instruction set for most current CPUs, ARM is mostly used in smartphone/tablet CPUs.

Assembly is a programming language that is a human-readable version of CPU instructions, so if you want to learn the instruction set, look into their version of Assembly. For example here's a wikipedia page about x86 assembly.

It's not important to learn any of this for programming purposes, but it can help if you want to truly understand your program and get to the next level as a programmer.

What is data?

A bit is a single electric signal or state somewhere in your computer, it is either 1 (high) or 0 (low). You don't need to care how the computer is able to have bits (think of them as microscopic electronic light switches), the important thing to know is that data is 1s and 0s. The storage of bits is called memory.

A bit alone can't do very much, so memory is usually interacted with in bytes: a group of 8 bits. By changing the bits in a byte, that byte can be made to represent 256 different things.

The most common example is to make bytes represent text characters, for example the ASCII specification says that the bits 01000101 mean "6", and the bits 00110110 mean "E", and so on (click here for the full table if you're curious). Almost all text in computers is ASCII or some derivative (such as UTF-8), so you don't need to remember any of it. For example if you add text into your code, the compiler will automatically translate the characters into the correct ASCII bytes.

You could write your own text system that uses completely different bits to represent "6" and "E", ASCII is just a commonly agreed way to do it. There's some values in a byte that don't represent useful ASCII characters, the game Dwarf Fortress for example uses those values to represent it's graphics. It's completely up to you how to use your data to do interesting things.

You can go further by grouping bytes, for example 4 bytes can be used to represent a typical integer; a number with 4,294,967,296 different possible values. When you're writing programs, it is important to be at least somewhat aware of what kind of data you're using: when you put an integer somewhere, you're putting in 4 bytes worth of data. If there's another integer next to it in memory then it would be 4 bytes away, if you want space for 10 integers then you would need 40 bytes of memory...