09-c数组的遍历

#include <stdio.h>

 

int main(int argc, const char * argv[]) {

    // 取出数组中所有的值称之为遍历

    int scores[6] = {1, 23, 44, 66, 71, 88, 99 , 2};

  

    // 注意在遍历数组的时候尽量不要把遍历的次数写死

    // 遍历多少次应该由数组来决定也就是说遍历多少次应该通过数组计算得出

   

    // 动态计算数组的元素个数

    int length = sizeof(scores) / sizeof(scores[0]);

    

    for (int i = 0; i < length; i++) {

        printf("scores[%i] = %i\n", i,scores[i]);

    }

    return 0;

}

 

posted @ 2016-03-02 15:29  wc&Home  阅读(273)  评论(0)    收藏  举报