14 changed files with 85 additions and 5 deletions
@ -1,6 +1,6 @@ |
|||
#include <iostream> |
|||
|
|||
int main() |
|||
{ |
|||
std::cout << "Hello World!\n"; |
|||
} |
|||
//int main()
|
|||
//{
|
|||
// std::cout << "Hello World!\n";
|
|||
//}
|
@ -0,0 +1,76 @@ |
|||
#include <iostream> |
|||
#include <vector> |
|||
using namespace std; |
|||
|
|||
typedef struct { |
|||
int a; |
|||
int* p; |
|||
char c; |
|||
short s; |
|||
double d; |
|||
bool b; |
|||
short sArr[4]; |
|||
}struct1; |
|||
|
|||
typedef struct { |
|||
short sh; |
|||
struct1 s1; |
|||
char c; |
|||
}struct2; |
|||
|
|||
typedef struct { |
|||
char c; |
|||
vector<int> vec; |
|||
short s; |
|||
}struct3; |
|||
|
|||
void test() { |
|||
int i = 10; |
|||
struct1 s1 = { |
|||
1234, |
|||
&i, |
|||
'c', |
|||
123, |
|||
123.4, |
|||
true, |
|||
{1, 2, 3, 4} |
|||
}; |
|||
|
|||
cout << "size of struct1 : " << sizeof(s1) << endl; |
|||
cout << "offset of a : " << offsetof(struct1, a) << endl; |
|||
cout << "offset of p : " << offsetof(struct1, p) << endl; |
|||
cout << "offset of c : " << offsetof(struct1, c) << endl; |
|||
cout << "offset of s : " << offsetof(struct1, s) << endl; |
|||
cout << "offset of d : " << offsetof(struct1, d) << endl; |
|||
cout << "offset of b : " << offsetof(struct1, b) << endl; |
|||
cout << "offset of sArr : " << offsetof(struct1, sArr) << endl; |
|||
cout << "--------------" << endl << endl; |
|||
|
|||
struct2 s2; |
|||
s2.sh = 42; |
|||
s2.c = 'f'; |
|||
|
|||
cout << "size of struct2 : " << sizeof(s2) << endl; |
|||
cout << "offset of s1 : " << offsetof(struct2, s1) << endl; |
|||
cout << "offset of c : " << offsetof(struct2, c) << endl; |
|||
cout << "--------------" << endl << endl; |
|||
|
|||
struct3 s3; |
|||
s3.c = 'A'; |
|||
s3.s = 678; |
|||
cout << "size of struct3 : " << sizeof(s3) << endl; |
|||
cout << "offset of c : " << offsetof(struct3, c) << endl; |
|||
cout << "offset of vec : " << offsetof(struct3, vec) << endl; |
|||
cout << "offset of s : " << offsetof(struct3, s) << endl; |
|||
cout << "--------------" << endl << endl; |
|||
|
|||
for (int j = 0; j < 100; j++) { |
|||
s3.vec.push_back(j + 1); |
|||
} |
|||
|
|||
cout << "done" << endl; |
|||
} |
|||
|
|||
int main() { |
|||
test(); |
|||
} |
Binary file not shown.
@ -1,2 +1,2 @@ |
|||
CPP_Learn.cpp |
|||
MemoryAlignment.cpp |
|||
CPP_Learn.vcxproj -> E:\22020100011_LXB\Projects\VisualStudio\CPP_Learn\x64\Debug\CPP_Learn.exe |
|||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue