The teacher said that the array variable can be regarded as a const pointer variable, in the end is "can be considered", or "is" pointer?
Use procedural evidence to illustrate your point of view.
(Hint: If all operations on a const pointer can be made to an array variable, and the result is consistent, it means that the variable is a pointer; If an operation cannot be done, or the result is inconsistent, it is not a pointer)
#include <stdio.h> intMain () {intA[] = {1,1,2,3,4,5,6,7,8,9,0,};int *constp = &a[0];printf("sizeof (a) = %d , sizeof (p) = %d \ n"), sizeof (a), sizeof (p));//sizeof(a) shown as -, which is the entire length of the array, sizeof (p) is displayed as8; Is the length of the pointerprintf("main:p = %p\ n", p);printf("main:a = %p\ n", a);//In the main function is still the first address of the array a[ -] =Ten;printf("main:a[13] = %d\ n", a[ -]); p[ -] =Ten;printf("main:p[13] = %d\ n", p[ -]);//Sum can be executed successfully in the main function (A, One); }intSumintA[],intLen) {intsum =0;inti =0;int *constp = &a[0];// int *constA = &a[0];//[Error]' A 'Redeclared as different kind of symbol (a re-declared as different types of symbols)//int *constp = &a[0];//[Error] redefinition of' P '(P repeat definition)//The above two hints are different errors, stating that the array parameter is not actually a constant pointer of this type//int* A = &a[0]; -[Error]' A 'Redeclared as different kind of symbol//int *constp = &a[0];//[Error] redefinition of' P 'Description array parameter is not a pointerprintf("p = %p\ n", p);printf("a = %p\ n", a);//He was pointing to an array of p[1] =Ten;printf("p[1] = %d\ n"-P:1]); a[1] =Ten;printf("a[1] = %d\ n", a[1]);//Whichever of the above executes is the same, and can be executed, which means that the variable is modified, the access variable is the same a[ -] =Ten;printf("a[13] = %d\ n", a[ -]); p[ -] =Ten;printf("p[13] = %d\ n", p[ -]);//This shows that a also does not store information about his length, it is just an address, like P, two without warning, can compile the same result for(i =0; i < len;i++) {sum + = A[i]; }printf("sizeof (a) = %d \ n", sizeof (a));//By compiling look to see sizeof (a) is still8, from this point of view, the passed array parameter is exactly the same as the constant pointerreturnSum }//From the above test, when the array variable as a parameter, it is not a strict pointer, not a constant pointer, but he can be seen as a pointer, and the operation of the constant pointer can be applied to the array variable//when the array variable is not a parameter, that is, it is in the main function, it has two meanings, When used on sizeof, it seems to be considered an array as a whole, but in other cases it can be treated as a constant pointer.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Relationship of array variables and pointers