#include <iostream> using namespace std; int main() { int yams[3]; yams[0] = 7; yams[1] = 8; yams[2] = 6; int yamcosts[3] = {20,30,5}; cout << "Total yams ="; cout << yams[0] + yams[1] + yams[2] <<endl; cout << yamcosts[1]<<endl; int total = yams[0] * yamcosts[0] +yams[1] * yamcosts[1]; total = total + yams[2] * yamcosts[2]; cout << "The total yam expense is "<<total<< " cents./n"; cout << " Size of yams array = " << sizeof yams <<" bytes./n"; cout << " Size of one element = " << sizeof yams[0]<<" bytes./n"; cout << " the length of yams array is " << (sizeof yams) / (sizeof yams[0])<<endl; cout << " the length of yams array is " << (sizeof yams) / (sizeof *yams)<<endl; cout << " the length of yams array is " << (sizeof yams) / (sizeof(int))<<endl; double test[3] = {12.2,13.5,14.0}; cout << " the length of test array is " << (sizeof test)/(sizeof test[0])<<endl; cout << " the length of test array is " << (sizeof test)/(sizeof *test)<<endl; cout << "test : " << test <<endl; //数组名放在sizeof后面可以代表整个数据从而求出数组所占空间 cout << "test = " << *test <<endl; //但实际上它做为指针是指向数组中的第一个元素 cout << "test + 1 : " << (test + 1) << endl; //数组名加1指针会得到下一个数组的地址 cout << "test + 1 = " << *(test + 1) << endl; // int cards[4] = {1,2,3,4}; //合法 // int hand[4]; //合法 // hand = {3,4,5,6} //不合法 // hand = cards; //不合法 指针间不允许这样做 // return 0; }