Pointer
Pointers and Arrays
Pointers and strings
Pointers and functions??
Pointers and Arrays
1. Array Name: array element First address
eg
int array[3]={1,3,6};
Here array constant equals &array[0]
2.int *p = A;
int *p = 0;
int a[]={0};
3.int *p = A;
All point to the first address of the array
What's *p? * (p+1) Yes? (*p) +1 yes?
* (P+1) decided to move down a few bytes is type
4. The pointer can be used when the array name
P[1] = 3;
Constant equals a[1]; constant equals * (p+1); constant equals * (a+1)
5. The difference between a pointer and an array
1) The occupied space is different
Pointer: only related to the operating system number of bits
Array: Related to the number and type of elements
2) The array name is a constant address and cannot be re-directed (cannot be assigned)
The pointer can be re-pointing
can a pointer count the number of elements in a group?
A: The string, the character array can end with ' s ', other types can not
to calculate the length of a string by pointer
Char string[10] = "IPhone";
char *p4 = string;
* (p+1) = ' V '; Manipulating single characters
printf ("%s", string);
printf ("%s", p4+1); Manipulate the entire character print phone
int count = 0;
while (* (P4 + count)! = ') ' {
count++;
}
printf ("%d", count);
int COUNTN =sizeof (string)/sizeif (char);
How to output all strings
Char *strings[3] = {"IOS", "Android", "Win8"};
for (int i = 0; i < 3; i++)
{
printf ("%s", Strings[i]);
}
Note: You can modify the character array with characters (you can adjust the position, etc.), but you cannot modify the constant string
That is, a single character in iOS
Pointers and functions and structures
Use the pointer to find the learner in the array of students with gender as a male, with an increase of 10 points and a score of 100 points over 100 points
typedef struct{
Char name[20];
char gender;
Char namel[20];
Float score;
} Student;
void Manstudents (Student *mstu, int count);
void Manstudents (Student *mstu, int count)
{
for (int i = 0; i < count; i++) {
if ((mstu+i)->gender = = ' m ') {
((mstu+i)->score) = ((mstu+i)->score) +10;
if (((mstu+i)->score) > 100) {
(mstu+i)->score = 100;
}
}
}
}
Macro
#define MUL (A, A) ((A) * (B))
Summarize
1) The pointer variable is the variable that holds the address, the assignment of the pointer variable, which means that the pointer is heavy pointing
2) The array name represents the first address of the array, and it is a constant address and cannot be modified
3) When a function is called, the parameter copies the value of the argument
Pointer pointer to array pointer with string pointer to function struct body and pointer macro