Data Structure Pointer review:
#include <stdio.h>voidMain () {inta[5] = {8,2,3,4,5}; //a[3] = = * (3+a)printf ("%d\n", *(3+a));//A[3] 4printf"*a is actually a[0]:%d\n", *a);//8//the address is continuous.printf"%p\n", A +1); printf ("%p\n", A +2); printf ("%p\n", A +3);}
A one-dimensional array name is a pointer constant that holds the address of the first element of a one-dimensional array, and its value cannot be changed.
A one-dimensional array name points to the address of the first element of the array. (get) modifies an array to pass in the length of the address and array of the first element.
#include <stdio.h>voidShow_array (int*p,intLen) {p[0] = -1; inti; for(i =0; i < Len; i++) {P[i]= P[i] +1; printf ("%d\n", P[i]); }}intMainvoid){ inta[5] = {1,2,3,4,5}; Show_array (A,5);//A is equivalent to &a[0], &a[0] is itself an int * type return 0;}
To modify the value of an argument through a function:
#include <stdio.h>void f (int *p) { ;} int Main (void) { int; F (&i); printf ("%d\n", i); return 0 ;}
Structure usage Overview: Structs have only attributes and no methods. A struct is a transition of a class. Why is there a struct? in order to represent some complex data, the common basic type does not meet the requirements. What is a struct? A struct is a composite data type that users define themselves according to their actual needs.
#include <stdio.h>#include<string.h>structStudent//defines a new data type{ intSID; Charname[ $]; intSage; }; //semicolons cannot saveintMainvoid){ //defines a data type that is a struct student variable St structStudent st = { +,"Zhangsan", -}; printf ("%d%s%d\n", St.sid, St.name, st.sage); St.sid= About; strcpy (St.name,"Lisi"); St.sage= A; printf ("%d%s%d\n", St.sid, St.name, st.sage); return 0;}
To be Continued ...
C language pointers and structures for review of data structures