Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Don't pointers have types? For example, int*p only defines the type of pointer as integer, not the type of pointer variable.
Don't pointers have types? For example, int*p only defines the type of pointer as integer, not the type of pointer variable.
The essence of a pointer is a memory address, so from this point of view, it can be considered that a pointer is untyped. But the memory pointed to by this address can store any type of data you want. For example, int* can store data of type int, and char* can store data of type char. From this point of view, you can think of it as typing.

In addition, most operations using pointers in general coding are string operations, because when data is stored in memory, it is basically a continuous memory space, so the pointer mentioned above is actually only the first address of this continuous memory space, and it is not considered as the end of this data until "\0" appears. Other places where pointers are used are basically used when defining parameters.

On the topic of memory allocation, it is generally aimed at the pointer char*. There are many functions in standard C to complete memory allocation, such as malloc (). The memory length you want to apply for is directly passed to malloc as a parameter. When defining it, it is similar to the following form: char * p = malloc (100);

Of course, you can also define a char array in advance, such as: char a [100]; Then define a pointer to it, for example: char * p = &;; a; Where "&"is an address symbol, you can get the first address of this array and assign it to the pointer P.