In these few pages so far on pointers, we have covered a lot of territory, but it is important territory. We still have a lot of material to cover so stay in tune as we continue this important aspect of C. Load the next file named pointer2.c and display it on your monitor so we can continue our study.
main( )
{
char strg[40],*there,one,two;
int *pt,list[100],index;
strcpy(strg,"This is a character string.");
one = strg[0]; /* one and two are identical */
two = *strg;
printf("The first output is %c %c\n",one,two);
one = strg[8]; /* one and two are identical */
two = *(strg+8);
printf("The second output is %c %c %c\n",one,two);
there = strg+10; /* strg+10 is identical to strg[10] */
printf("The third output is %c\n",strg[10]);
printf("The fourth output is %c\n",*there);
for (index = 0;index < 100;index++)
list[index] = index + 100;
pt = list + 27;
printf("The fifth output is %d\n",list[27]);
printf("The sixth output is %d\n",*pt);
}
In this program we have defined several variables and two pointers. The first pointer named "there" is a pointer to a "char" type variable and the second named "pt" points to an "int" type variable. Notice also that we have defined two array variable named "strg" and "list". We will use them to show the correspondence between pointers and array names.
main( )
{
char strg[40],*there,one,two;
int *pt,list[100],index;
strcpy(strg,"This is a character string.");
one = strg[0]; /* one and two are identical */
two = *strg;
printf("The first output is %c %c\n",one,two);
one = strg[8]; /* one and two are identical */
two = *(strg+8);
printf("The second output is %c %c %c\n",one,two);
there = strg+10; /* strg+10 is identical to strg[10] */
printf("The third output is %c\n",strg[10]);
printf("The fourth output is %c\n",*there);
for (index = 0;index < 100;index++)
list[index] = index + 100;
pt = list + 27;
printf("The fifth output is %d\n",list[27]);
printf("The sixth output is %d\n",*pt);
}
In this program we have defined several variables and two pointers. The first pointer named "there" is a pointer to a "char" type variable and the second named "pt" points to an "int" type variable. Notice also that we have defined two array variable named "strg" and "list". We will use them to show the correspondence between pointers and array names.

