Structures Definition

Learn about structures to write better, more organized code.


Let’s say we want a program to perform some mathematical data manipulation on two-dimensional points. We may be interested in calculating values such as:

  • The distance between 2 points.
  • The midpoint of a segment, given 2 points.
  • The equation of a line, given 2 points.
  • The slope of a line.

To provide a concrete example, let’s write code to calculate the distance between 2 points. The distance between points (x1,y1)(x1, y1) and (x2,y2)(x2, y2) is (x2x1)2+(y2y1)2\sqrt{(x2 - x1)^{2} + (y2 - y1)^{2}}.

Get hands-on with 1200+ tech skills courses.