Pages: [1]   Go Down
Author Topic: char variable  (Read 1104 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
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


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

« Last Edit: October 28, 2010, 10:29:26 am by 10base2 » Logged

Seattle, WA USA
Online Online
Brattain Member
Karma: 631
Posts: 50107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The statement
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.

Pages: [1]   Go Up
Jump to: