Big Tuto: Program with the C language
From theory to practice
Chapter 4: RAM
Tutorial presented by: The Ludovyc and Jérémie F. Bellanger (Jay)
The Ludovyc
Publication: March 11, 2014
Last revision: March 9, 2025
In this chapter we will go through some theory and discuss RAM. ![]()
I- What is RAM?
You've probably heard of it, RAM is the acronym for Random Access Memory. If you upgrade your computer a bit, you've probably already changed the memory sticks in your PC. Well, you had then added RAM to your PC (perhaps without knowing it?). ![]()

Examples of RAM memory sticks for desktop and laptop PCs (yes, they are a bit old...)
Random ? But, then, it's like in Dungeons & Dragons, the computer rolls a die and makes a random throw until it lands on the right variable?!? ![]()
Hum...?? No!
It rather means that you can access any variable wherever it is in memory (without having to start from the beginning each time).
Indeed, RAM is organized into slots (= drawers) of 1 byte (8 bits, the equivalent of a character in ASCII). The processor accesses the data thanks to their address in memory (a bit like the postman finds you with your address in fact
).
You can therefore imagine that the RAM of your computer is a sort of gigantic library filled with millions of books with archivists who move at the speed of electricity to go and get what you ask them: read, write or edit a book and put it in its right place on the shelf.

II- Let's have fun using RAM to store a character in memory
Well, I had planned to develop the functioning of memory even more but I realize that this will not necessarily be very useful for you to start in C. So we will instead make a small program which will have the goal of putting a character in memory, then going to search for it and displaying it (what do you mean: "Phew!"?
).
Here is the program:
//To access the printf() and system() functions.
//Note that stdlib is normally not needed,
//but Visual Studio won't compile without it.
# include <stdio.h>
# include <stdlib.h>
int main ( )
{
//We create a variable of type char in memory,
//named c and we store the character a in it
char c = 'a' ;
printf ( "%c\n" , c ) ; //We display the value of c in the console
/* Instruction to add in console mode (or under VS) to have
"Press any key to continue...", already included in Code::Blocks */
system ( "PAUSE" ) ;
}
Important note: comments
You will have noticed that our program above contains comments. These are useful to help (re)read a program, by indicating what each part of the program does and how it works. Of course, these comments will not be compiled, and you must therefore use the tags, otherwise the compiler will take them for code, and crash. Generally speaking, you should not hesitate to comment your code as much as possible, so as to make it readable to others, and also to yourself, if you come back to it some time later.
Here are the two types of comments with their tags:
// Single line comment.
/* For a multi-line comment,
open it with the /* tag and close it with */
But now let's get back to our program:
So it puts the value of the variable "c" in memory. "c" is both the name of the variable and its address (well, at compilation, the linker takes care of converting the name into a memory address for us
).
We could have given it any other name but we chose "c" to remind ourselves that it is a char. And this is a good method: it is always better to have explicit variable names that reflect what they contain. So for example, in a role-playing game, it will be easier to know what a variable Heros_HP contains rather than h32! ![]()
Now let's look at the contents of the variable c. We store the letter 'a' there, so that we can then write it using a printf(). However, you should know that each letter is actually represented by a number in memory. Indeed, the computer only knows how to count. ![]()
The letter a corresponds to the number 97, so we could also have written: char c = 97; ! ![]()
You will also notice the difference in the use of the printf() function. We put %c\n as the first parameter, where %c indicates that we are going to display the contents of a variable as a character (c for char) and \n indicates to the console that it should do a line break after displaying the character (also called a carriage return, like in the days of old typewriters). Finally, the second parameter is the variable that we are going to display in place of %c.

We can now make a small variation, to illustrate the fact that the letter a corresponds to the number 97:
//To access the printf() and system() functions
# include <stdio.h>
# include <stdlib.h>
int main ( )
{
//We create a variable of type char in memory,
//named c and we store 97 (the number of the letter a) in it
char c = 97 ;
//We create a second variable of type char in memory,
//named c1 and we store the character a in it
char c1 = 'a' ;
printf ( "%c\n%c1\n", c , c1 ) ; //We display the value of c in the console
/* Instruction to add in console mode (or under VS) to have
"Press any key to continue...", already included in Code::Blocks */
system ( "PAUSE" ) ;
}
And here is the result in our console:

You'll notice that variable names must be unique, so for our second variable, we simply named it c1.![]()
And there you go, see you soon for the next chapter!![]()

English
Français