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
Copy file name to clipboardExpand all lines: examples/List/ManageElements/ManageElements.ino
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
#include<List.hpp>
2
2
3
-
// Create a mutable list
3
+
// Create an immutable list
4
4
List<int> list;
5
5
6
6
voidsetup() {
@@ -14,20 +14,21 @@ void setup() {
14
14
Serial.println();
15
15
16
16
// Get the first element
17
-
Serial.print("The value of the first element with the get() method and '*' is: ");
18
-
int firstElement = *list.get(0); // Here, have to be the '*' to get the int Value, because otherwise a pointer (memory address) will be get.
19
-
Serial.println(firstElement);
17
+
Serial.print("The value of the first element with the getValue() method is: ");
18
+
Serial.println(list.getValue(0)); // The most comfortable way to get the first elements value is to call the getValue() method. You cannot get the address of the element with the getValue() method!
20
19
21
20
// Get the first element (alternative)
22
21
Serial.print("The value of the first element with the [] operator is: ");
23
-
firstElement = *list[0]; // The '[]' Operator is a synonym for the get() method.
22
+
intfirstElement = list[0]; // The '[]' Operator is a synonym for the getValue() method.
24
23
Serial.println(firstElement);
25
24
26
-
// Get only the value of the first element
27
-
Serial.print("The value of the first element with the getValue() method is: ");
28
-
Serial.println(list.getValue(0)); // The more comfortable way to get only the first elements value is to call the getValue() method. You cannot get the address of the element with the getValue() method!
25
+
// Get the first element (alternative)
26
+
Serial.print("The value of the first element with the getPointer() method and '*' is: ");
27
+
int *firstElementPtr = list.getPointer(0); // Here, have to be the '*' to get the int Value, because otherwise a pointer (memory address) will be returned.
28
+
Serial.println(*firstElementPtr);
29
+
free(firstElementPtr); // free the pointer because it is an immutable list
29
30
30
-
Serial.println("As you can see, there are three possible ways to get the value. Choose your favorite one :)");
31
+
Serial.println("As you can see, there are three possible ways to get the value. The last way is not for beginners because you have to handle pointers.");
0 commit comments