// myarray.c #include #include typedef struct _myarray *myarray; struct _myarray { int size; // how big the array is int* data; // pointer to the array }; // example of a function declaration int f(int x){ return 2*x; } // create a new myarray myarray new_myarray(){ int i; myarray newarray = malloc(sizeof(struct _myarray)); newarray->size = 100; // default size newarray->data = malloc(100 * sizeof(int)); for (i=0; i<100; i++){ newarray->data[i] = 0; } return newarray; } // get one element of the array int get(int i, myarray ma){ return ma->data[i]; } // set one element of the array void set(int i, int value, myarray ma){ ma->data[i] = value; } int main(){ myarray george = new_myarray(); set(3, 20, george); // set i=3 to value 20 set(5, 30, george); // set i=5 to value 30 printf(" get(3, george) is %d \n", get(3, george)); printf(" get(5, george) is %d \n", get(5, george)); return 0; }