Pointer Resource for Arduino Author: Alexander Brevig Contact: alexanderbrevig@gmail.com
In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address. A pointer references a value stored elsewhere in memory, and obtaining or requesting the value to which a pointer refers is called dereferencing the pointer. Wikipedia
It enables the programmer to communicate directly to an already initialized instance of a datatype.
For instance, it might come in handy to have a class being able to swap which Serial object that does Serial communications. By using pointers this is possible.
#include "Print.h" //datatype* variablename = ⌖ Print* printer = &Serial;
//this is the equivalent of Serial.print
printer->print("print using the Serial object"); //notice the -> as opposed to .
//change target adress (or which adress to point to)
printer = &Serial2;
//this is the equivalent of Serial2.print
printer->print("print using the Serial2 object");
When do we use pointers?
Passing by referance & or * will increase performance when using datatypes that are larger than 8bit.
| Part of AlphaBeta Resources. | |
| Last Modified: | May 09, 2009, at 05:14 AM |
| By: | AlphaBeta |