how to elements of a list in c

Solutions on MaxInterview for how to elements of a list in c by the best coders in the world

showing results for - "how to elements of a list in c"
Naelle
17 Jul 2017
1#include <stdio.h>
2
3int main (int argc, char * argv[])
4{
5    int i = 0;
6    int list[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
7    int run = 1;
8    int length_of_list; // the number of elements that the list contains
9    length_of_list = sizeof(list) / sizeof(int); // getting the number
10    
11    while (run){ //printing the list
12    printf("The list is: %d\n", list[i]);
13    i = i + 1;
14    if (i == length_of_list){ //check if the list has ended
15        printf("The list has ended!\n");
16        break; // exit the loop
17    } 
18    }
19
20    return 0;
21}