Answers for "how to elements of a list in C"

C
2

how to elements of a list in C

#include <stdio.h>

int main (int argc, char * argv[])
{
    int i = 0;
    int list[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int run = 1;
    int length_of_list; // the number of elements that the list contains
    length_of_list = sizeof(list) / sizeof(int); // getting the number
    
    while (run){ //printing the list
    printf("The list is: %d\n", list[i]);
    i = i + 1;
    if (i == length_of_list){ //check if the list has ended
        printf("The list has ended!\n");
        break; // exit the loop
    } 
    }

    return 0;
}
Posted by: Guest on July-02-2021

Code answers related to "how to elements of a list in C"

Code answers related to "C"

Browse Popular Code Answers by Language