int main(int argc, char** argv, char** envp) { rectangle* r=create_rectangle(5,6); printf("r is at %p\n", r); printf("the area of the rectangle is %d\n", rectangle_area(r)); rectangle_destroy(r); rectangle* r2=(rectangle*)alloca(sizeof_rectangle()); construct_rectangle(r2, 7, 8); printf("r2 is at %p\n", r2); printf("the area of the rectangle is %d\n", rectangle_area(r2)); int i; rectangle* myrectangles=(rectangle*)malloc(100*sizeof_rectangle()); char* p=(char*)myrectangles; for(i=0;i<100;i++) { construct_rectangle((rectangle*)p, 7, 8); p+=sizeof_rectangle(); } p=(char*)myrectangles; for(i=0;i<100;i++) { rectangle_destroy((rectangle*)p); p+=sizeof_rectangle(); } return EXIT_SUCCESS; }
int main(int argc, char** argv, char** envp) { rectangle* r=create_rectangle(5,6); printf("the area of the rectangle is %d\n", rectangle_area(r)); rectangle_destroy(r); return 0; }