declaring const strings
-
static const char str[3] = {'a','b','c'}; static const char str[3] = "abc"; what is the difference between the above two? or are they same? is the first one null terminated? why do some folks use the first one when the second one is easier.
-
static const char str[3] = {'a','b','c'}; static const char str[3] = "abc"; what is the difference between the above two? or are they same? is the first one null terminated? why do some folks use the first one when the second one is easier.
I think the second is null terminated. I used something similar to the first, but I specified the characters in hexidecimal form like this: static const char cmd[3] = { 0x0A, 0x10, 0x0D }; I had to use characters not easily expressible on a regular Qwerty keyboard and I also used only characters 2 and 3 sometimes. Character arrays were convenient because the serial port sends 1 byte at a time and characters are 1 byte long.
-
static const char str[3] = {'a','b','c'}; static const char str[3] = "abc"; what is the difference between the above two? or are they same? is the first one null terminated? why do some folks use the first one when the second one is easier.
-
static const char str[3] = {'a','b','c'}; static const char str[3] = "abc"; what is the difference between the above two? or are they same? is the first one null terminated? why do some folks use the first one when the second one is easier.