-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructures.c
More file actions
57 lines (45 loc) · 1.21 KB
/
structures.c
File metadata and controls
57 lines (45 loc) · 1.21 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <string.h>
// syntax of structures
struct employee
{
int code; // declears a user defined data tyoe
float salary;
char name[10];
}; // ; is important
// using typedef in structures
struct complex{
float real;
float img;
};
typedef struct complex{
float real;
float img;
} complexNo;
void show(struct employee e);
int main()
{
// arrays and strings can hold similar data
// Structures can hold disimilar data
// initialize strucutres in main function
struct employee e1; // structure variable or source
strcpy(e1.name, "umang");
e1.code = 444;
e1.salary = 71.22;
// arrays of strucutres
struct employee facebook[100]; // an array of structures
// we can access the data using:
facebook[0].code = 100;
facebook[1].code = 101;
// And so on
// pointers in structures
struct employee *ptr;
ptr = &e1;
// print the structure elements using:
printf("%d",(*ptr).code);
// arrow operator - insted of writing (*ptr).code we can:
ptr->code
// here -> is known as the arrow operator
// passing strucutres to a function
return 0;
}