-
Notifications
You must be signed in to change notification settings - Fork 28
/
9structs.c
39 lines (28 loc) · 1.1 KB
/
9structs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
int main (){
/******************************
* structure declaration
* ***************************/
// int x, y;
struct { int x; int y;} point1, point2;
printf("\nEnter coordinates of a point: ");
scanf("%d %d", &point1.x, &point1.y);
printf("\npoint1 = (%d, %d)", point1.x, point1.y);
// can be initialized during declaration
struct { int x; int y;} point3 = {22, 33};
struct { int x; int y;} point4 = {.y=2, .x=34}; // designated initializer
printf("\npoint4 = (%d, %d)", point4.x, point4.y);
/******************************
* structure tag declaration
* ***************************/
struct cplx {int real; int imag;};
struct cplx c1 = {33, 55}, c2 = {4, 6};
printf("\n c1 = %d + %di", c1.real, c1.imag);
/******************************
* structure typedef declaration
* ***************************/
typedef struct { char name[10]; float gpa; int year;} student;
student s1 = {"somename", 2.3, 3};
printf("\ns1 name = %s, gpa = %f, year = %d", s1.name, s1.gpa, s1.year);
return 0;
}