You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠== You can decompress Drawing data with the command palette: 'Decompress current Excalidraw file'. For more info check in plugin settings under 'Saving'
Copy file name to clipboardExpand all lines: content/Drafts/Chapter 1.md
+34-6Lines changed: 34 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,16 +4,44 @@ title: "Chapter 1: Introduction, How Computers Work, Memory Layouts, Data Types
4
4
5
5
This chapter is going to be a doozy. We'll start off by priming you with some of the prerequisite knowledge you need to know surrounding C.
6
6
7
-
Let's start off with an example:
7
+
Let's start off with a snippet that we'll be using throughout this chapter.
8
8
9
9
```C
10
10
#include<stdio.h>
11
-
12
-
intmain(){
13
-
printf("Hello world!\n");
14
-
return 0;
11
+
intmain(int argc, char **argv){
12
+
printf("hello world\n");
13
+
return 0;
15
14
}
15
+
```
16
+
17
+
This is most probably everyone's first C program. There's a lot to cover, and for today it's a whirlwind tour around all the important aspects you need to know surrounding this program. As an overview, we'll be covering:
18
+
19
+
1. How to create an executable out of written C code.
20
+
2. C Code Compilation.
21
+
3. A simple mental model of a process, and computer memory.
22
+
4. Data types in C, and their operations.
23
+
24
+
Again, it's quite a few disparate topics, so we'll be dipping our toes only a little bit in every topic.
25
+
26
+
# Creating programs from C code
27
+
28
+
So let's say we had that snippet written down somewhere. How do we actually "run" the code? There are many ways we can get this down, but here's one of the simplest ways: An online compiler called [Godbolt](https://godbolt.org). We've used their sharing feature to actually already pre-write in the snippet for you, so you can pop open the site [here](https://godbolt.org/z/d7oK4sKEM). If you visit it, you should be greeted by this on the page.
29
+
30
+
![[godbolt-hello-world.png]]
16
31
32
+
On the left pane is where you'd write code, and the website will actually automatically try compiling whatever has been written in it. For now, since it has been pre-filled with our snippet, it has automatically compiled the the code. On the bottom right pane, you'll see the following:
33
+
34
+
```
35
+
Program returned: 0
36
+
Program stdout
37
+
hello world
17
38
```
18
39
19
-
This is most probably everyone's first C program. There's a lot to cover, and for today it's a whirlwind tour
40
+
Ignoring the first 2 lines for now, you'll notice that the program has somehow output "hello world".
41
+
42
+
Let's look at the most likely line that made this happen: **line 4**. It reads `printf("hello world\n");`. What's that all about?
43
+
44
+
`printf` stands for "print format", and this is a **function** that we will **call** to output stuff to the screen.
0 commit comments