Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Differences between indicator array and array indicators and their respective explanations
Differences between indicator array and array indicators and their respective explanations
differences between pointer array and array pointer and their respective explanations

pointer array is an array of pointers (the main body is an array), which means that there is an array, and each element in the array is a pointer type. (Similarly, a plastic array means that every element in the array is a plastic).

an array indicator is an indicator of an array (the main body is an indicator), which means that there is an indicator, and this indicator points to an array. What is the difference between array indicators and indicator arrays?

I paroled you to understand the difference between an array and an indicator (this is the important thing). An array indicator is an indicator, pointing to an array, while an indicator array is an array, and every element in it is an indicator. Calculate two n*3 matrices

# include <: stdio.h>

int main() {

double Mat[3][5];

int i=, j=;

input matrix

for(i=; i< 3; i++) {

for(j=; j< 5; j++) {

scanf("%lf",& Mat[i][j]);

}

}

display matrix

for(i=; i< 3; i++) {

for(j=; j< 5; j++) {

printf("%.1lf ",Mat[i][j]);

}

printf("\n");

}

find the sum of each line

for(i=; i< 3; i++) {

double sum = ;

double* p = *(Mat+i);

for(j=; j< 5; j++)

sum += p[j];

printf("%.1lf\n",sum);

}

return ;

} The difference between an array pointer and an array reference as an argument

can change the value pointing to the space and return the main function.

the array pointer is the incoming address, that is, a new pointer variable (argument variable) is created and the address of the array is stored in it. In the program, the value of this argument can be changed.

array reference directly transmits the original variables, and there are no new variables

. That is to say, the former has one more variable allocation and release process than the reference, which is slightly inefficient and can be almost ignored.

The advantage of the former is that it is compatible with C, and the code does not need to be changed when it does not support reference. And the programming is more flexible. C++ new indicator array

new int*[1]

The difference between two-dimensional array and one-dimensional indicator array

Two-dimensional array has so many elements of the same type multiplied by two dimensions, while one-dimensional indicator array has only so many indicator elements of a certain type. There seems to be no comparability between the two, with different dimensions and different element types. How to understand the array indicator ++*p

Hello

First of all, the indicator P should be an int type.

Since the priority of * is greater than++,*p is executed first, and then ++

*p is the value of the element pointed by the indicator P

+*p is the self-addition of the element pointed by the indicator P

So *. stdio.h>

#define N 1

int main()

{

char *p[1]; Or use malloc to dynamically allocate space

char array[N][1]; The type space pointed by the allocation indicator array is

int n,i;

scanf("%d",& n); n < N

for(i=; i< n; i++)

{

scanf("%s",array[i]);

}

for(i=; i< n; i++)

{

p[i] = array[i];

printf("%s\n",p[i]);

}

return ;

}

Your program does not allocate the space of the pointed type for the pointer array, so using it directly will lead to a segment error, that is, it will generate a wild pointer. Difference between array and pointer

array

location 123

location 1 456

pointer = memory address pointing to this array.