will be read-only starting December 31st, 2018. For more info please look at this Forum Post

Pointer Resource for Arduino
Author:  Alexander Brevig



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.

Declaration and Creation

#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.


Information about this page

Part of AlphaBeta Resources.
Last Modified: December 26, 2015, at 11:24 PM
By: pert