Can you please explain to me what is happening here?
char data[128]; // Create char array of size 128.
long * ptr; // Create a pointer.
ptr = (long *) data; // ??
Mainly, what does the (long *) mean?
Does it mean that the data is of type char, and I am casting the reference to data as a reference to a long?
Thank you.
It is casting the data pointer as a pointer to a long.
The line:
will allocate 128 bytes of memory and treat that data as characters. The code:
allocates a pointer to a long, and sets that pointer to point at the memory allocated by
char data[128];.You can reference this memory by
data[x]to get the xth character starting at the beginning of this memory block. Or you can reference this memory byptr[x]to get the xth long starting at the beginning of this memory block. Just note that each long takes up more storage than each character. It is probably 8 bytes – so you can go up todata[127]orptr[15].