/*NBs: -only pointers can hold addresses (thats why they are used) -The keyword char declares 8-bit values, int declares 16-bit values, short declares 16-bit values and long declares 32-bit values. Unless the modifier unsigned is present, the variables declared by these statements are assumed by the compiler to contain signed values. You could add the keyword signed before the data type to clarify its type. float => 32-bit floating numbers not recommended double => 64-bit floating numbers not recommended */ /************************ Array References *************************/ //the expression &data[3] yields the address of the fourth element. //Notice too that &data[0] and data+0 and data are all equivalent. //It should be clear by analogy that &data[3] and data+3 are also equivalent. short x,*pt,data[5]; /* a variable, a pointer, and an array */ void Set(void){ x=data[0]; /* set x equal to the first element of data */ x=*data; /* set x equal to the first element of data */ pt=data; /* set pt to the address of data */ pt=&data[0]; /* set pt to the address of data */ x=data[3]; /* set x equal to the fourth element of data */ x=*(data+3); /* set x equal to the fourth element of data */ pt=data+3; /* set pt to the address of the fourth element */ pt=&data[3]; /* set pt to the address of the fourth element */ /************************ Pointers and Array Names *************************/ //The examples in the section suggest that pointers and array names //might be used interchangeably. And, in many cases, they may. C will //let us subscript pointers and also use array names as addresses. //In the following example, the pointer pt contains the address of an //array of integers. Notice the expression pt[3] is equivalent to *(pt+3). short *pt,data[5]; /* a pointer, and an array */ void Set(void){ pt=data; /* set pt to the address of data */ data[2]=5; /* set the third element of data to 5 */ pt[2]=5; /* set the third element of data to 5 */ *(pt+2)=5; /* set the third element of data to 5 */