How can I find the number of elements in an array?

前端 未结 14 1193
广开言路
广开言路 2020-12-02 15:01

I have an int array and I need to find the number of elements in it. I know it has something to do with sizeof but I\'m not sure how to use it exac

14条回答
  •  情歌与酒
    2020-12-02 15:39

    i mostly found a easy way to execute the length of array inside a loop just like that

     int array[] = {10, 20, 30, 40};
     int i;
     for (i = 0; i < array[i]; i++) {
        printf("%d\n", array[i]);
     }
    

提交回复
热议问题