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)); } |
...previous | up (conts) | next... |