Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to add element in list c

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int * numbers = malloc(6*sizeof(int));

    for(int ii = 0; ii < 6; ++ii) {
        numbers[ii] = 5;
    }

    numbers = realloc(numbers, 7*sizeof(*numbers));
    if(!numbers) {
        printf("Memory allocation failed, sorry dude!
");
        exit(1);
    }

    numbers[6] = 7;

    for(int ii = 0; ii< 7; ++ii) {
        printf("%d
", numbers[ii]);
    }

    free(numbers);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #element #list
ADD COMMENT
Topic
Name
8+8 =