Skip to content

Latest commit

 

History

History
26 lines (24 loc) · 602 Bytes

File metadata and controls

26 lines (24 loc) · 602 Bytes

User defined types

  • enum: used to enumerate things, e.g. weekdays, for example:
    enum week
    {
    	monday, tuesday, wednesday, thursday, friday, saturday, sunday
    };
    enum week day;
    
  • struct: Save a collection of variables (a structure), e.g. for complex numbers:
    struct complex:
    {
    	double real;
    	double imaginary;
    };
    c1 = {1.0, 2.0};
    
    //can be accessed through .
    int real_part = c1.x;
    
    //for pointers, can be accessed through ->
    struct complex *ptr_to_c1 = & c1;
    int real_part = ptr_to_c1->x
    
    • ptr_to_c1->x is equivalent to (*ptr_to_c1).x