Pages: [1]   Go Down
Author Topic: char variable  (Read 1088 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: October 28, 2010, 10:29:26 am by 10base2 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The statement
Code:
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.
Logged

Pages: [1]   Go Up
Jump to: