C language complex expressions, advanced use of pointers

1
An array of pointers is an array
Array pointers are pointers: pointers point to an array.


analyze:
int *p[5];
int (*p)[5];
int *(p[5]);//It is the same as the first one, the parentheses are redundant, and it is correct to use it.
The first step is to find the core: who is the defined symbol
The second step is to find the combination: if the core is combined with *, it means a pointer; if the core is combined with [], it means an array; if the core is combined with (), it means it is a function.
The third step is to expand outward: After finding the core, combine
2 function pointers layer by layer from the inside to the outside:
Function pointers are essentially pointers, and they still occupy 4 bytes, and all pointers are 4 bytes.
The essence of a function is a piece of code that is continuously distributed in memory. The C language uses the function name to represent the first address of the function


C language is a strongly typed language (each variable has its own variable type), and the compiler can do strict type checking for us.


The biggest difference between a function name and an array name is that adding & does not have the same effect and meaning when the function name is used as an rvalue; but the array name is different
.

struct student{
           int age;
           char name[20];
        };//A type is defined at this time, which does not consume memory.
        struct student s1; //A structure variable is defined at this time, and memory needs to be allocated.


typedef struct student{
int age;
           char name[20];
}student; //At this time, two types of the same type but different names are defined. One is struct student; one is student.


Note: typedef int *PTNT; const PTNT p2; is equivalent to int *const p2;
               typedef int *PTNT; PTNT const p2; is equivalent to int *const p2;


4 double pointers:
There is no essential difference between a double pointer and a single pointer, both of which are pointer variables and occupy 4 bytes.


char **p1;
char *p2;
char a;
p2=&a;
  p1=&(&a);//Error: because &a is a constant, & cannot be used for constants;
p1=&p2;//Yes: because p2 is a char* pointer variable, you can use &;


The double pointer points to the address of the single pointer;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325528969&siteId=291194637