top of page

03 Variables

string

Text strings can be represented in two ways. you can use the String data type, or you can make a string out of an array of type char and null-terminate it. This entry describes the latter method. For more details on the String object, which gives you more functionality at the cost of more memory, see the "String()" entry.


Possibilities for declaring strings

Declare an array of chars without initializing it as in Str1

Declare an array of chars (with one extra char) and the compiler will add the required null character, as in Str2

Initialize with a string constant in quotation marks; the compiler will size the array to fit the string constant and a terminating null character, Str3

Initialize the array with an explicit size and string constant, Str4


Null termination

Generally, strings are terminated with a null character (ASCII code 0). This allows functions (like Serial.print()) to tell where the end of a string is. Otherwise, they would continue reading subsequent bytes of memory that aren’t actually part of the string.


Single quotes or double quotes?

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

char Str1[15];


char Str2[8] = {'A', 'r', 'd', 'u', 'i', 'n', 'o'};


char Str3[] = "Arduino";


char Str4[8] = "Arduino";



© 2021 Odyssey Navigator. All rights reserved.

bottom of page