Structures

A structure is a derived data type --- elements may be of different types.

Example of declaration:
    struct class_record {
        int size;
        float average_mark;
        int pass_mark, number_pass;
      };

    struct class_record year_1, year_2, year_3;

A full programme:
    #include <stdio.h>
    #include <string.h>

    struct stock_item{
        char name[21];
        float cost;
        int number, min_level;
      };

    float value_of(struct stock_item item) {
        float value = item.number * item.cost;
        return value;
      }

    main() {
        struct stock_item hammer;

        strcpy(hammer.name, "hammer");
        
        hammer.cost = 2.15;
        hammer.number = 10;
        hammer.min_level = 25;

        printf("Value of hammers in stock = %f\n", value_of(hammer));
      }


...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_course_crash_in_c/_reml_grp/index.reml
On: 3/3/2003 at 17:43:41
Options: reml2 -i noindex -l long -o html -p multiple