what is the difference between unsigned char in[] and const unsigned char in[]
Thanks
Printable View
what is the difference between unsigned char in[] and const unsigned char in[]
Thanks
const means that the data cannot be changed.
in contains the characters "qwerty" which cannot be changed.Code:const unsigned char in[] = "qwerty";
in again contains the characters "qwerty" but the characters in the array can be changed.Code:unsigned char in[] = "qwerty";
In the above, the line highlighted produces a compile error as the code is trying to change the q to a z but in is defined as const so changes are not allowed. The in2 change is allowed as in2 is not defined as const.Code:const unsigned char in[] = "qwerty";
unsigned char in2[] = "qwerty";
in[0] = 'z';
in2[0] = 'z';
Hopes that helps.:)