

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: SnekObjects
incomplete
2: Integer
incomplete
3: Float
incomplete
4: String
incomplete
5: Vector3
incomplete
6: Array
incomplete
7: Set
incomplete
8: Get
incomplete
9: Length
incomplete
10: Add
incomplete
This lesson's interactive features are locked, please to keep using them
Now we're going to do our first object that has something... additional allocated. When we allocate memory for a "snek object", that reserves memory for the object itself. Small data types like integers and floats are stored directly in the object, so there's no need for additional memory allocation.
Strings, however, are a different story. Strings in C are just arrays of characters, and because they can be any length, we need to dynamically allocate memory for the string data separately from the object itself.
char *my_string = "hello world";
In the example above, my_string is a pointer to a character array. The character array contains:
h
e
l
l
o
w
o
r
l
d
\0
The extra spot at the end with the \0 is the null terminator. It's how C knows where the string ends.