]> git.piffa.net Git - sketchbook_andrea/blob - basic_programming/pointers_c/pointers/pointers.ino
b148b7007625fd81c417250368f56fe7eb4cba91
[sketchbook_andrea] / basic_programming / pointers_c / pointers / pointers.ino
1
2 int *ptrNumber ;
3 void setup() {
4   // put your setup code here, to run once:
5   Serial.begin(9600);
6
7 }
8
9 void loop() {
10   int number = 5;
11
12
13   Serial.print("number is ");
14   Serial.println(number);
15   Serial.print("The lvalue for number is: ");
16   Serial.println((long) &number, DEC);
17
18   Serial.print("---- Pointer was ");
19   Serial.println(*ptrNumber);
20   Serial.print("The lvalue for ptrNumber is: ");
21   Serial.println((long) &ptrNumber, DEC);
22   Serial.print(" and the rvalue is ");
23   Serial.println((long) ptrNumber, DEC);
24
25   ptrNumber = &number ;
26   Serial.println("Assigned!");
27
28   Serial.print("===== Pointer was ");
29   Serial.println(*ptrNumber);
30   Serial.print("The lvalue for ptrNumber is: ");
31   Serial.println((long) &ptrNumber, DEC);
32   Serial.print(" and the rvalue is ");
33   Serial.println((long) ptrNumber, DEC);
34
35   *ptrNumber = 6 ;
36   Serial.print("**** Pointer value is: ");
37   Serial.println(*ptrNumber);
38   Serial.println(number);
39
40   Serial.flush();
41   exit(0);
42
43 }
44
45