C:数组的要点和技巧

技巧:

1.数组的初始化

  两种方法

    (1)

  for (i = 0; i < 10; i++)
    {
        cout[i] = 0;
    }

    (2)

   cout[ ] = {0}

2.对于零散的数组中值的赋值

   cout[ ] = {[1] =2, 4,[5]=6 }

   输出为 0 2 4 0 0 6

3.search函数的应用(用于找key在数组中的位置)

  search(int key, int a[], int length)   作为函数的时候 a[]中不能在[]给出数组的大小

  如果在数组中,返回位置,不在则返回-1

 4. 指针与数组的应用

       int a[4] = {1, 2, 3, 4};
       int i;
      for (i=0; i<4; i++)
      {
         printf("%d ",*(a+i));
      }
      return 0;

   *(a+i)表示的是a[i]

 

  

posted on 2019-05-08 19:05  zhaoy_shine  阅读(145)  评论(0编辑  收藏  举报

导航