1 #include <iostream>
2 #include <cstdlib>
3 using namespace std;
4
5 int main()
6 {
7 struct {
8 int a;
9 long b;
10 float c;
11 double d;
12 }var;
13 int a[5] = {0};
14 cout << "a address:" << (int*)a << endl;
15 cout << a << endl;
16 cout << "int: " << sizeof(int) << endl;
17 cout << "long: " << sizeof(long) << endl;
18 cout << "float: " << sizeof(float) << endl;
19 cout << "double:" << sizeof(double) << endl;
20
21 cout << &(var.a) << endl;
22 cout << &(var.b) << endl;
23 cout << &(var.c) << endl;
24 cout << &(var.d) << endl;
25 int *pa = (int*)malloc(sizeof(int));
26 long *pb = (long*)malloc(sizeof(long));
27 float *pc = (float*)malloc(sizeof(float));
28 double *pd = (double*)malloc(sizeof(double));
29 cout << pa << endl;
30 cout << pb << endl;
31 cout << pc << endl;
32 cout << pd << endl;
33
34 delete pa;
35 delete pb;
36 delete pc;
37 delete pd;
2 #include <cstdlib>
3 using namespace std;
4
5 int main()
6 {
7 struct {
8 int a;
9 long b;
10 float c;
11 double d;
12 }var;
13 int a[5] = {0};
14 cout << "a address:" << (int*)a << endl;
15 cout << a << endl;
16 cout << "int: " << sizeof(int) << endl;
17 cout << "long: " << sizeof(long) << endl;
18 cout << "float: " << sizeof(float) << endl;
19 cout << "double:" << sizeof(double) << endl;
20
21 cout << &(var.a) << endl;
22 cout << &(var.b) << endl;
23 cout << &(var.c) << endl;
24 cout << &(var.d) << endl;
25 int *pa = (int*)malloc(sizeof(int));
26 long *pb = (long*)malloc(sizeof(long));
27 float *pc = (float*)malloc(sizeof(float));
28 double *pd = (double*)malloc(sizeof(double));
29 cout << pa << endl;
30 cout << pb << endl;
31 cout << pc << endl;
32 cout << pd << endl;
33
34 delete pa;
35 delete pb;
36 delete pc;
37 delete pd;
38 }