Arduino Programming Language: String


string (char array)


The text can be represented in two ways : you can use the String data type or array of characters, which is the method explained in this page.

Null termination 
Usually, the strings are terminated with a null character (ASCII code 0). This allows functions (such as Serial.print ()) to know the end of a string and, therefore, do not continue to read the next byte of memory that are not actually part of the string. 
This means that the string must have space for another character of the text you want it to contain. 
Note that you can have a string without a final null character but this could be the problem.

Single quotes and double quotes

Strings are always defined inside double quotes ("Abc") and characters are always defined inside single quotes('A').

Wrapping long strings

You can wrap long strings like this:

char myString[] = "This is the first line" 
" this is the second line" 
" you can continue....";


  • Declare an array of chars (with one extra char) and the compiler will add the required null character:
    char name_of_array[];
  • Declare an array of chars (with one extra char) and the compiler will add the required null character:
    char name_of_array[7]={'p','h','r','a','s','e'};

  • Explicitly add the null character:
    char name_of_array[7]={'p','h','r','a','s','e','\0'};

  • Initialize with a string constant in quotation marks; the compiler will size the array to fit the string constant and a terminating null character:
    char name_of_array[]="phrase";

  • Initialize the array with an explicit size and string constant:
    char name_of_array[7]="phrase";

  • Initialize the array, leaving extra space for a larger string:
    char name_of_array[12]="phrase";


  • name_of_array: name assigned to the array;




It is often convenient, when working with large amounts of text, to setup an array of strings. Because strings themselves are arrays, this is in actually an example of a two-dimensional array.

char* myStrings[]={"This is string 1", "This is string 2", "This is string 3",
"This is string 4", "This is string 5","This is string 6"};

void setup(){

void loop(){
for (int i = 0; i < 6; i++){

In the code above, the asterisk after the datatype char "char*" indicates that this is an array of "pointers". All array names are actually pointers, so this is required to make an array of arrays.


char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};

Based on the reference originally written by Arduino Community, and