This repo contains a set of beginning exercises and tasks to help you learn the C programming language and basic CPU architecture.
These tasks are meant for beginners who know very basic programming in a high-level language. Basic knowledge of functions, variables, strings, loops, etc. will be assumed by the exercises, though C-specific syntax will not be.
Important
As a prerequisite, please do the "Learn the Basics" portion of the Learn C exercises (at least complete up to the "Functions" lesson).
Avoid the temptation to look at solutions or to use AI - these exercises are designed to help you learn by doing, so try to solve them on your own, and type them out manually.
We will install different C compilers depending on the operating system (OS) you use. The main operating systems are macOS (Apple), Windows (Microsoft), and Linux.
Tip
The most popular C compilers (like MSVC) are really a combined C and C++ compiler, since C++ is a superset of C. This means that C programs are also valid C++ programs.
The clang
C/C++ compiler should automatically be avaialable to use.
The gcc
C/C++ compiler should automatically be available to use. If it's not,
install the "build-essentials" or "gcc" package for you Linux distro.
E.g., for Ubuntu, do:
sudo apt install build-essentials
clang
can also be installed on Linux if you prefer clang
.
Tip
If you are on Windows, but want to use a Linux environment, consider using Window's WSL (Windows Subsystem for Linux). This gives you a full Linux installation on Windows, and you can then follow the Linux instructions.
For Windows, we will install the native msvc
C/C++ compiler.
- Go to the Visual Studios downloads page
- Download "Build Tools for Visual Studio 2022"
- Run
vs_BuildTools.exe
- Under the "Workloads" tab, select "Desktop development with C++"
- Click
Install
- Search for
Developer PowerShell for VS 2022
and run it - In PowerShell, change the directory to where you downloaded Nando Lang
cd <path-to-nando-lang>
Note
For official documentation on how to install a C compiler on Windows, see Walkthrough: Compile a C program on the command line
To download Nando lang, go to https://github.com/hintron/nando-lang/releases and download the source code. Extract it to a directory
(Don't use Git to clone the repo. We're keeping it simple.)
First, determine the terminal program to use.
- macOS:
terminal
- Linux:
konsole
- (If using WSL, you will already be using a terminal program.)
- Windows: Developer PowerShell for VS 2022
- (You must use a "Developer" version of PowerShell, or else
msvc
will not be available.)
- (You must use a "Developer" version of PowerShell, or else
Next, go inside the nando-lang directory you just downloaded:
cd <path-to-nando-lang-directory>
Tip
Use tab completion to quickly select file paths in the terminal and as a sanity check that the file exists.
Then, build the checker program with the following command, depending on which OS you are on:
# If on Linux:
gcc src/main.c -o main
# If on macOS
clang src/main.c -o main
# If on Windows
cl src/main.c
Next, run the checker with no arguments:
./main
This will display an introductory blurb with your first instructions. These instructions will tell you what exercise to first start editing.
Edit your source code files using a coding text editor like VSCode or NeoVim.
Once you have edited the exercise, compile it in your terminal with this command:
# Linux
gcc exercises/<exercise>.c -Wall
# macOS
clang exercises/<exercise>.c -Wall
# Windows
cl exercises/<exercise>.c /W4 /Fea.out.exe
Replace <exercise>.c
with the exercise you are working on.
Tip
The -Wall
//W4
are optional - they will display warnings that could indicate problems
in your code, but these warnings do not prevent the code from being compiled.
This will compile your code and generate a.out
if compilation succeeded.
a.out
is your compiled program. Each time you compile, a.out
will get
overwritten with the latest compiled changes to your program.
Run a.out
to make sure your program does what you wanted:
./a.out
When you are satisfied that it does what you want, give it to the checker to run and see if you pass the exercise!:
./main a.out
If you pass, the checker will tell you the next exercise to work on.
For a basic C syntax reference, see
En espanol:
- Lenguaje C
- Wikilibros - Programación en C
- Learn C
- Aprende C en 45 minutos (curso desde cero)
- El Manual para principiantes C
Pointers
En espanol: