#include <stdio.h>
struct point {
int x;
int y;
};
struct rectangle {
struct point upper_left;
struct point lower_right;
};
double calcul_area(struct rectangle a) {
double width = a.lower_right.x - a.upper_left.x;
double height = a.upper_left.y - a.lower_right.y;
return width * height;
}
struct rectangle r;
r.upper_left.x = 3;
r.upper_left.y = 9;
r.lower_right.x = 12;
r.lower_right.y = 2;
int main() {
printf("the size of rectangle is %f", calcul_area(r));
}
this code is for calculate the area of rectangle int the axis $x$,$y$.i don't want to talk about the idea of the code ,but just i want to understand why this error is shown.note that the code work fine when i make the above part of code under the main function,but when i put it before the main function i see the error
struct rectangle r;
r.upper_left.x = 3;
r.upper_left.y = 9;
r.lower_right.x = 12;
r.lower_right.y = 2;