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 do the 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 in your computer is just programs, and the compiler is no exception, it's not even a very complicated program. A compiler takes your files, reads the text in it, 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 CPU instruction is just a couple bytes of data (see 'What is data?' below). When you load that byte 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. A "program", also known as an "application" or "app", is any file that has a bunch valid CPU instructions in it.

If you're interested in this, search for "cpu instruction set". An instruction set is a set of rules that define which bits represent which actions in the CPU (for example moving data between 2 places or adding 2 values together), x86 is the instruction set for most current CPUs, ARM is the one used in smartphone/tablet CPUs. It's not particularly important to learn any of it for programming purposes though, but it can help if you want to truly understand your program.

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 also isn't very useful for general programming unless you want to make a compiler or modify executables for some reason.

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 though, thus 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 it represent text characters, for example the ASCII specification says that the bits 01000101 mean "6", and the bits 00110110 mean "E", and so on. Almost all text in computers is ASCII or some derivative (such as UTF-8), and thus your compiler and other programs will deal with it automatically.

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...