Skip to content

Instantly share code, notes, and snippets.

@ishankhare07
Created July 22, 2018 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishankhare07/542eb9d528e13d7019a27c45dff26782 to your computer and use it in GitHub Desktop.
Save ishankhare07/542eb9d528e13d7019a27c45dff26782 to your computer and use it in GitHub Desktop.
Perfectly valid C - designated initializers
#include <stdio.h>
#include <math.h>
typedef struct point {
int x;
int y;
} Point;
float distance(Point *p1, Point *p2) {
return sqrt(
pow((p2->y - p1->y), 2)
+ pow((p2->x - p1->x), 2)
);
}
int main(void) {
float d = distance(
&(Point) {
.x = 0,
.y = 0,
},
&(Point) {
.x = 3,
.y = 4,
}
);
printf("%f\n", d);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment