Created
July 22, 2018 13:14
-
-
Save ishankhare07/542eb9d528e13d7019a27c45dff26782 to your computer and use it in GitHub Desktop.
Perfectly valid C - designated initializers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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