Hope the results will not surprise you! Small programs can also be a great wisdom!
#include <iostream>using namespace Std;int main () {double* (*a) [3][6];cout<<sizeof (a) <<endl;//4 A is an array pointer 32 bits below is 4 bytes cout<<sizeof (*a) <<endl;// *a is the whole array cout<<sizeof (**a) <<endl; The **a is the first row of the two-dimensional array, this one-dimensional array cout<<sizeof (***A) <<endl;//4 ***a is the first element inside the double*cout<< sizeof (****A) <<endl; 8 ****a is double this type return 0;}
Look at a program again.
We all know that when an array is a parameter, it degrades the address of the first element.
int Sum (int (*i) [6])//array pointer {int sumofi = 0;for (int j = 0; J < sizeof (*i)/sizeof (**i); j + +)//sizeof (*i) = 24{ //size Of (*i)/sizeof (int) Sumofi + = (*i) [j];} return Sumofi;} int Sum2 (int (&i) [6])//array reference {int sumofi = 0;for (int j = 0; J < sizeof (i)/sizeof (*i); j + +)//sizeof (i) = 24{ //// sizeof (i)/sizeof (int) Sumofi + = I[j];} return Sumofi;} int main () {int allages[] = {1, 2, 3, 4, 5, 6};cout<<sum (&allages) <<endl;cout<<sum2 (allages) < <endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
A program of thinking can test your pointer to understand the skill of the program