I would like to know why some things have to be within a pair of Apostrophes and others within Quotation marks?
void trythis(){
char myChar = 'Stuff';
String myString = "Blah";
int myInteger = '22';
Serial.print(myChar );
Serial.print(myString );
Serial.print(myInteger );
}
Character literals use a single quote. So when you're dealing with char
, that's 'x'
.
String literals use double quotes. So when you're dealing with string
, that's "x"
.
A char
is a single UTF-16 code unit - in most cases "a single character". A string is a sequence of UTF-16 code units, i.e. "a piece of text" of (nearly) arbitrary length.
Your final example, after making it compile, would look something like:
int myInteger = 'x';
That's using a character literal, but then implicitly converting it to int
- equivalent to:
char tmp = 'x';
int myInteger = tmp;
See more on this question at Stackoverflow