You are looking at lesson 8. Your place is still lesson 3, task 1: Conditions.
Memory is numbered bytes. How many bytes char, int, double and a pointer take, and why the size of long differs between Windows and Linux.
So far a variable was "a box with a name". In this topic you see where that box actually is.
Memory is a long row of bytes. A byte is 8 bits, and every byte has its own number, its address. A variable takes several bytes in a row, and its address is the number of its first byte.
The addresses in the drawing are made up: real ones are long hexadecimal numbers, and different on every run.
sizeof tells how many bytes a type or a variable takes. Its value has the type size_t and is printed with %zu:
printf("int: %zu bytes\n", sizeof(int));
| type | bytes | note |
|---|---|---|
char |
1 | always |
int |
4 | which is why the largest int is 2147483647 (topic 2) |
double |
8 | |
int * (a pointer) |
8 | on a 64-bit computer |
long |
4 or 8 | 4 on Windows, 8 on Linux |
The last row is the reason never to guess a size: write sizeof.
&x is the address of the variable x. You can print it with %p:
printf("%p\n", (void *)&x);
In CLion on Windows you'll see something like 000000000061FE1C, on Linux 0x7ffd5e8a3c4c. The number may differ every time, so the program's logic doesn't depend on it. Addresses are easier to look at in the debugger: you'll do that in step 4.
An array's boxes lie one after another (topic 6). &t[1] is exactly sizeof(int) bytes after &t[0], so the address of t[i] is worked out at once: the start + i * sizeof(int). That's why the index starts at 0.
Each one ticks itself when you do it.
All six done. You know your way around.
It is laid out like CLion: the same panels in the same places. This tour shows each one, and you can reopen it any time with Tour.
Switches the left panel: Lesson plan, Project files, Changes. Click the active icon again to hide the panel.
In CLion: the tool window bar runs down the left edge, too.
This part is not on this task: it appears when a task needs it.
Every task in this lesson. Now marks your place. Clicking a task only lets you look; it never moves your place. Project files and Changes open here too.
In CLion: this spot holds the Project view (the file tree).
This part is not on this task: it appears when a task needs it.
Opens the file for your task by itself. A tab appears for each file the step opens. The breadcrumbs above the code show the folder.
In CLion: the same editor tabs and breadcrumbs.
This part is not on this task: it appears when a task needs it.
Diff shows what changed, like git diff: red is the old code, green the new.
In CLion: the diff view in the Commit window looks the same.
This part is not on this task: it appears when a task needs it.
Terminal for build commands, Database to see your tables. They open by themselves when a task needs them. Drag the top edge to resize.
In CLion: Terminal, and the Database tool window.
This part is not on this task: it appears when a task needs it.
What to do now, right above the code, so you never miss it. Numbered notes in the code explain the important lines. Details shows what you should see and a hint.
In CLion: no equivalent: this is your lecturer's guide.
This part is not on this task: it appears when a task needs it.
Done is the only button that moves you forward. Look back lets you review without losing your place.
This part is not on this task: it appears when a task needs it.
Guided, Focus code or Floating. You can drag the panel edges too. Your layout is remembered for next time.
In CLion: you can also rearrange and hide tool windows.
This part is not on this task: it appears when a task needs it.
Six small missions. Each one ticks itself when you do it, so you know you have found everything.