Arrays in the 1.C language have their own specific types
2. The type of the array has the element type and the group size together determine
Renaming an array type in the 3.C language by typedef
typedef type (name) [size];
Array Pointers
1. Array pointers are used to point to an array
2. The array name is the starting address of the first element of the array, but not the starting address of the array
3. The starting address of the array can be obtained by taking the address & function to the array name
4. Array pointers can be defined by array type:
arraytype* pointer;
5. It is also possible to define directly: type (*pointer) [n];p ointr The array pointer variable name, type is a pointer to the types of arrays, n is the size of the array to point to.
The array pointer is the address of the first element of the array, which is a pointer, except that the pointer is a const pointer and is read-only.
#include <stdio.h>typedef int (AINT5) [5];typedef float (AFLOAT10) [10];typedef char ( ACHAR9) [9];//defines 3 array types Int main () { aint5 a1; float farray[10]; afloat10* pf = &farray;//afloat10 is an array type, achar9 carray; char (*PC) [9] = &carray; char (*PCW) [4] = carray; int i = 0; printf ("%d, %d\n", sizeof (AINT5), sizeof (A1)); for (i=0; i<10; i++) { (*PF) [i] = i; } for (i=0; i<10; i++) { printf ("%f\n", farray[i]); } printf ("%0x, %0x, %0x\n", &carray, pc+1, pcw+1);}
Array of pointers
1. An array of pointers is a normal array
2. Each element in the pointer array is a pointer
3. Array pointer definition: type* parray[n];type* The type of each element in the array; Parray is an array name; n is an array size
The plain is an array in which the elements are all pointer types.
Main function
1.main functions can be understood as functions called by the operating system
2. You can pass parameters to the main function when executing the program
#include <stdio.h>int main (int argc, char* argv[], char* env[])/* Number of command line arguments, array of command-line arguments, array of environment variables */{ int i = 0; printf ("============== begin argv ==============\n"); for (i=0; i<argc; i++) { printf ("%s\n", argv[i]); } printf ("============== end argv ==============\n"); printf ("\ n"); printf ("\ n"); printf ("\ n") ; printf ("============== begin env ============= =\n "); for (i=0; env[i]!=null; i++) { printf ("%s\n", env[i]); } printf ("============== end env ==============\n");}
Summarize:
-
An array pointer is essentially a pointer
-
The value that the array pointer points to is the address of the array
-
An array of pointers is essentially an array
-
The type of each element in the pointer array is a pointer
The difference between pointer arrays and array pointers and the main function