Dynamically-expanding array in C I'm learning C, specifically OOP in C. As practice, I wrote a dynamically-expanding array.

dynarray.h

#ifndef DYNARRAY_H
#define DYNARRAY_H

typedef struct DynArray {
    int length,
        capacity,
        *arr;

    void (*extend)(struct DynArray *dynArr);
    void (*insert)(struct DynArray *dynArr, int val);
    void (*print) (struct DynArray *dynArr);
} DynArray;

void DynArray_extend(DynArray* dynArr);
void DynArray_insert(DynArray* dynArr, int value);
void DynArray_print(DynArray* dynArr);

#endif


dynarray.c

#include &lt;stdlib.h&gt;
#include "dynarray.h"

DynArray* createDynArray() {
    DynArray* newDynArray = malloc(sizeof(DynArray));
    newDynArray-&gt;capacity = 10;
    newDynArray-&gt;arr = malloc(sizeof(int)*newDynArray-&gt;capacity);
    newDynArray-&gt;length = 0;

    newDynArray-&gt;extend = DynArray_extend;
    newDynArray-&gt;insert = DynArray_insert;
    newDynArray-&gt;print  = DynArray_print;
}

void DynArray_extend(DynArray* dynArr) {
    int newCapacity = dynArr-&gt;capacity * 2,
        *newArr = malloc(sizeof(int)*newCapacity),
        i;

    dynArr-&gt;capacity = newCapacity;

    for (i = 0; i &lt; dynArr-&gt;length; i++) {
        newArr[i] = dynArr-&gt;arr[i];
    }
}

void DynArray_insert(DynArray* dynArr, int val) {
    if (dynArr-&gt;length == dynArr-&gt;capacity) {
        dynArr-&gt;extend(dynArr);
    }

    dynArr-&gt;arr[dynArr-&gt;length] = val;
    dynArr-&gt;length = dynArr-&gt;length + 1;
}

void DynArray_print(DynArray* dynArr) {
    int i;
    for (i = 0; i &lt; dynArr-&gt;length; i++) {
        printf("%d\n", dynArr-&gt;arr[i]);
    }
}


And this is an example application of the dynamic array (program.c):

#include &lt;stdio.h&gt;
#include "dynarray.c"

int main( void ) {
    int i = 0;
    DynArray* someDynArray = createDynArray();

    printf("Length  : %d\n", someDynArray-&gt;length);
    printf("Capacity: %d\n", someDynArray-&gt;capacity);

    for (i = 0; i &lt; 80; i++) {
        someDynArray-&gt;insert(someDynArray, i);
    }

    someDynArray-&gt;print(someDynArray);
}


I would like to know if there are any flaws in the style of implementing the abstract data type of the dynamically expanding array.
My 2 cents:


I believe createDynArray should return something.
The returned value of createDynArray might have a special value of NULL in case that one of the mallocs calls failed (this scenario should be covered by the code).
In the implementation of extend - consider using realloc instead of malloc and manual copy. If you insist on malloc perhaps using memcpy might be more elegant than a manual copy.
I'd move magic numbers to #defines: Initial Capacity (hard-coded to 10) and Growth Factor (2). Alternatively, they could be parameters to the createDynArray function
How would you free this struct? Perhaps you should add a "destructor" to be called before calling free with the struct pointer as a parameter.
In terms of functionality, other than printing this "array", how would the consuming programmer could get (or set) a specific item in this "array"?