1. Valid pointer operations include: Value assignment between pointers of the same type; addition or subtraction between pointers and integers; subtraction or comparison between two pointers pointing to elements in the same array. assign a pointer to 0 or a comparison operation between the pointer and 0.
Example 1:
# Define allocsize 10000
Static char allocbuf [allocsize];
Static char * allocp = allocbuf;
Char * alloc (int n)
{
If (allocbuf + allocsize-allocp> = N ){
Allocp + = N;
Return allocp-N;
}
Else
Return 0;
}
Void afree (char * P)
{
If (P> = allocbuf & P <allocbuf + allocsize)
Allocp = P;
}
Void swap (char * V [], int I, intj)
{
Char * temp;
Temp = V [I];
V [I] = V [J];
V [J] = temp;
}
2. character array
The character array ends with the null character '\ 0'. Therefore, the program can check the null character to find the end of the character array.
In array format:
Void strcpy (char * s, char * t)
{
Int I;
I = 0;
While (S [I] = T [I])! = '\ 0 ')
I ++;
}
In pointer format:
Void strcpy (char * s, char * t)
{
While (* s ++ = * t ++ )! = '\ 0 ')
;
}
3. pointer array and pointer
Char * PTR [maxlines]; // PTR is a one-dimensional array with maxlines elements. Each element is a pointer to a character type.
Char ** PTR; // pointer to the element pointer to which the Pointer Points. The element char data pointed to by the pointer
When the pointer array is output, printf ("% s \ n", * PTR ++) can be used );