←to practical programming

Note "structures"

Unlike arrays—which hold values (called elements) of the same type and refer to them by index—the structures hold values (called members) of possibly different types and refer to them by name.

The structures are declared using the following syntax,

struct struct_name {member_type_1 member_name_1; member_type_2 member_name_2; ...}

A variable to hold an instance of this structure is declared as

struct struct_name variable_name;

It can be initialized as

struct struct_name variable_name = {value_of_type1, value_of_type_2, ...};
or as
struct struct_name variable_name = {.member_name_1=value_of_type1, .member_name_2=value_of_type_2, ...};
The members are accessed using the dot-notation,
variable_name.member_name_1 = value_of_type_1;

To avoid typing struct struct_name all the time one can indroduce a new type,

typedef struct struct_name new_type;
new_type variable_name = {value_of_type1, value_of_type_2, ...};

For example,

#include"stdio.h"
struct komplex {double re; double im;};
const struct komplex I = {0,1};
typedef struct komplex komplex;
const komplex J = {.re=0,.im=1};
int main(){
	komplex z;
	z.re=1;
	z.im=2;
	printf("z=(%g,%g)\n",z.re,z.im);
	printf("I=(%g,%g)\n",I.re,I.im);
	printf("J=(%g,%g)\n",J.re,J.im);
return 0;
}