编译器有很多种,但它们都包含的典型的32位类型是:int,signed,signed int,unsigned,unsigned int,long,signed long,long int,signed long int,unsigned long,unsigned long int。尽量使用32位的数据类型,因为它们比16位的数据甚至8位的数据更有效率。
float x[VECLEN], y[VECLEN], z[VECLEN]; ...... for (unsigned int k = 1; k <; VECLEN; k ++) { x[k] = x[k-1] + y[k]; } for (k = 1; k <; VECLEN; k++) { x[k] = z[k] * (y[k] - x[k-1]); } float x[VECLEN], y[VECLEN], z[VECLEN]; ...... float t(x[0]); for (unsigned int k = 1; k <; VECLEN; k ++) { t = t + y[k]; x[k] = t; } t = x[0]; for (k = 1; k <; VECLEN; k ++) { t = z[k] * (y[k] - t); x[k] = t; } Switch 的用法
int days_in_month, short_months, normal_months, long_months; ......
switch (days_in_month) { case 28: case 29: short_months ++; break; case 30: normal_months ++; break; case 31: long_months ++; break; default: cout <;<; ";month has fewer than 28 or more than 31 days"; <;<; endl; break; } int days_in_month, short_months, normal_months, long_months; ......
switch (days_in_month) { case 31: long_months ++; break; case 30: normal_months ++; break; case 28: case 29: short_months ++; break; default: cout <;<; ";month has fewer than 28 or more than 31 days"; <;<; endl; break; } 所有函数都应该有原型定义