1 int xfun(int *a,int n)
 2 {
 3     int x = *a;//a的类型是int *,a+1跳动一个int的长度
 4     for (int *pa = a + 1; pa < a + n; pa++)//指向同一个类型的指针比较大小,相减是两者之间的元素个数
 5     {
 6         //string s = pa - a;// string接受const char*的单参构造函数不是explicit的,但编译器不能把int转换为string类型
 7         decltype(pa - a) t;
 8         int arr[3][4];
 9         decltype(arr) Type;
10         float f = pa - a;//因为float是四个字节,有效数字为6为,int转换为float可能丢失精度
11         cout << *pa << endl;
12         if (*pa > x)
13             x = *pa;
14     }
15     return x;
16 }
17 int main()
18 {
19     int x[5] = { 23, 46, 78, 55, 16 };
20     cout<<xfun(x, 5);
21 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-07-10
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
  • 2022-03-07
相关资源
相似解决方案