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 address (or which address 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 reference & or * will increase performance when using datatypes that are larger than 8bit.
Part of AlphaBeta Resources. | |
Last Modified: | December 26, 2015, at 11:24 PM |
By: | pert |