Пример #1
0
int main(int argc, char *argv[]) {
    struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
    struct Person *frank = Person_create("Frank Blank", 20, 72, 180);
    struct Person rhett;

    rhett.name = "Rhett Rogers";
    rhett.age = 27;
    rhett.height = 72;
    rhett.weight = 200;

    Person_print_stack(rhett);

    printf("Joe is at memory location %p:\n", joe);
    Person_print(joe);
    printf("Frank is at memory location %p:\n", frank);
    Person_print(frank);

    // make everyone age 20 years and print them again
    joe->age += 20;
    joe->height -= 2;
    joe->weight += 40;
    Person_print(joe);

    frank->age += 20;
    frank->weight += 20;
    Person_print(frank);

    rhett.age += 20;
    rhett.height += 1;
    rhett.weight -= 20;
    Person_print_stack(rhett);

    // destroy them both so we clean up
    Person_destroy(joe);
    Person_destroy(frank);

    return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
    // make two people structures
    struct Person *joe = Person_create(
            "Joe Alex", 32, 64, 140);

    struct Person *frank = Person_create(
            "Frank Blank", 20, 72, 180);

    // print them out and where they are in memory
    printf("Joe is at memory location %p:\n", joe);
    Person_print(joe);

    printf("Frank is at memory location %p:\n", frank);
    Person_print(frank);

    // make everyone age 20 years and print them again
    joe->age += 20;
    joe->height -= 2;
    joe->weight += 40;
    Person_print(joe);

    frank->age += 20;
    frank->weight += 20;
    Person_print(frank);

    // destroy them both so we clean up
    Person_destroy(joe);
    Person_destroy(frank);

    // create a struct on the stack
    struct Person stackyjoe = Person_create_stack(
            "Joe Mama", 32, 64, 140);

    Person_print_stack(stackyjoe);
    
    return 0;
}