-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstruct.cpp
More file actions
76 lines (61 loc) · 1.16 KB
/
struct.cpp
File metadata and controls
76 lines (61 loc) · 1.16 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdlib.h>
typedef struct tagNode
{
char *p;
int i;
}pNode;
struct point
{
int x;
int y;
};
struct node
{
int i;
struct node *p;
};
#define f(x) (x)*(x)
#define ff(x) x*x
#define fff(x) ((x)*(x)) //这种写法正确
typedef char *pStr;
char string[4] = "abc";
const char *p1 = string;
const pStr p2 = string;
int main(int argc, char const *argv[])
{
p1++;
printf("%s\n",p1);
p2++; //error: read-only variable is not assignable
int a=6, b=2, c, cc, ccc;
c = f(a);
cc = ff(a);
ccc = fff(a);
printf("c=%d cc=%d ccc=%d\n", c, cc, ccc);
c = f(a)/f(b);
cc = ff(a)/ff(b);
ccc = fff(a)/fff(b);
printf("c=%d cc=%d ccc=%d\n", c, cc, ccc);
node *np;
np = (node*)malloc(sizeof(node));
//node np;
np->i = 1;
printf("hhhhh:b%d\n",np->i);
node *oneNode;
oneNode = (node*)malloc(sizeof(node));
oneNode->i = 2;
np->p = oneNode;
printf("%0x\n", np->p);
printf("%0x\n", &np->p);
free(oneNode);
free(np);
point pt;
pt.x = 1;
pt.y = 2;
pNode tag;
tag.p = "hello";
tag.i = 2;
printf("%s\n", tag.p);
printf("%d\n", tag.i);
return 0;
}