C + + After studying for a while, I found that I had forgotten the most basic things, strcut (struct), Union (Union) I learned a bunch of things but forgot the two most basic;
Now you have a good time to re-learn the things here;
First, class (classes)
Class is used to define objects;
By default the member is private (private);
Members are not necessarily stored in the order of Declaration;
Ii. Strcut (structural body)
The structure is used to define the process or structure (and the combination of a bunch of attributes);
Members are public by default;
Members are stored in memory in the order they are declared, but not necessarily consecutively;
Iii. Union (Consortium)
A consortium (also known as a common body) is used to define certain special structures;
All members share a piece of memory, the size of the memory and the maximum decision of the length of the member;
Member variables are stored in memory in the order in which they are declared, and the memory is contiguous;
1#include <iostream>2 3 using namespacestd;4 5 Union IP_Address6 {7UnsignedintIP;8UnsignedCharr[5];9 };Ten One intMain () A { - ip_address ip1; -Ip1.ip =0x4544434241; thecout << Ip1.ip <<Endl; -cout << ip1.r[0] <<Endl; -cout << ip1.r[1] <<Endl; -cout << ip1.r[2] <<Endl; +cout << ip1.r[3] <<Endl; -cout << ip1.r[4] <<Endl; + return 0; A}
View Code
C + + Basics Comb--class, Struct, Union