-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs4.c
More file actions
52 lines (42 loc) · 1.18 KB
/
structs4.c
File metadata and controls
52 lines (42 loc) · 1.18 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
/* File: structs4.c
*
* Purpose: Illustrate pass by reference of structs using second solution
* to problem of passing struct args -- using typedef
* Input: None
* Output: struct member values
*
* Compile: gcc -g -Wall -o structs4 structs4.c
* Usage: ./structs4
*
* Note: This program has a few bugs . . .
*/
#include <stdio.h>
typedef struct {
double value;
int row;
int col;
} element_t;
void pass_struct(element_t* x_p);
int main(void) {
element_t element;
element.value = 5.5;
element.row = 6;
element.col = 10;
printf("element.value = %f\n", element.value);
printf("element.row = %d\n", element.row);
printf("element.col = %d\n", element.col);
pass_struct(&element);
printf("\nelement.value = %f\n", element.value);
printf("element.row = %d\n", element.row);
printf("element.col = %d\n", element.col);
return 0;
} /* main */
void pass_struct(element_t* x_p) {
printf("\nIn pass_struct\n");
printf("x.value = %f\n", (*x_p).value);
printf("x.row = %d\n", (*x_p).row);
printf("x.col = %d\n", (*x_p).col);
*x_p.value = 1.2;
*x_p.row = 10;
*x_p.col = 16;
} /* pass_struct */