Figure 5-2
Arrays and Pointers
However, what is far worse is if you try changing a value
outside of the size of the
array. For instance, if you were to include something like the following in your program,
the results could simply make your sketch break:
The pigeonhole
durations[10]
may be in use as some completely different variable. So
always make sure that you do not go outside of the size of the array. If your sketch starts
behaving strangely, then check for this kind of problem.
Morse Code SOS Using Arrays
Sketch 5-02 shows how you can use an array to make your emergency signal of SOS:
String literals are enclosed in double quotation marks. They are literal in the sense that the
string is a constant, rather like the
int
123.
As you would expect, you can put strings in a variable. There is also an advanced string
library, but for now you will use standard C strings, such as the one in sketch 5-03.
In C, a string literal is actually an array of the type
Dostları ilə paylaş: