Go Down

Topic: char variable (Read 1 time) previous topic - next topic

10base2

Oct 28, 2010, 04:58 pm Last Edit: Oct 28, 2010, 05:29 pm by 10base2 Reason: 1
I'm somewhat of a nube to Arduino and its IDE, but I do have a question in regards to the char variable/data type,  I'm using an RFID sketch that declares the following char variable:

char *goodCode = "0F030429F0";

but later on in the sketch when variable is called

Serial.println(goodCode);

it does so without *(asterisk), as a test I removed asterisk and received compile error - can anyone please explain why.

Thanks

PaulS

The statement
Code: [Select]
char *goodCode = "0F030429F0";
allocates some memory, stores some data in that memory location, and puts the address of that memory location in the variable goodCode. One would say that goodCode points to the string, hence the term pointer.

That memory consists of consecutive bytes. The first byte is offset 0 from the start of the memory location stored in goodCode, so it can be obtained using goodCode[0].  Other characters are at other offsets. The value in the [] is the offset from the beginning of the array.

Pointers and arrays are very closely linked, and can generally substitute for each other.

Go Up