// This is a first example of how you should create arrays. // In particular, look at function make_array, // and how it creates array x. // Compare to bad_example1.cpp. #include #include int * make_array(int length) { // bad way // int x[2]; // good way int * x = (int *) malloc(sizeof(int) * length); x[0] = 10; x[1] = 20; return x; } int main() { int * x = make_array(2); printf("x[0] = %d\n", x[0]); free(x); return 0; }