#include <stdio.h>
// Define a structure to represent a point in 2D space
struct Point {
int x;
int y;
};
int main(void) {
// Declare a structure variable and initialize its members
struct Point p = {1, 2};
// Print the values of the structure members
printf("x = %d, y = %d\n", p.x, p.y);
// Modify the structure members
p.x = 3;
p.y = 4;
// Print the modified values of the structure members
printf("x = %d, y = %d\n", p.x, p.y);
return 0;
}
This program defines a structure called Point
to represent a point in 2D space, with x
and y
members to represent the coordinates of the point. It declares a structure variable p
of type struct Point
and initializes its members. It then prints the values of the structure members and modifies them.
Here is an example of the output of this program:
x = 1, y = 2
x = 3, y = 4
0 Comments