I finished the last article I wrote was found not comprehensive enough, so, this article will continue on a content of the article, and add new things again, if there is what needs to add, please also pointing out all If you have studied these things, you can skip and a place to forget if after that you can return to continue their studies
Then we talk about the C language structure type, structure type in the C language have [array], [structure], [union], [enumeration type], let us look at each explained
- Array: Array everyone should know about the earliest type of construction, and why arrays are constructed type it, I do not know was how to learn, I'm going to tell you that now is, in fact, all of the arrays are one-dimensional arrays that our multi-dimensional arrays is how come it is because the elements of the array we can still be an array, so use this relationship, we can create a multidimensional array, then explain it briefly array:
. 1 #include <stdio.h> 2 . 3 int main ( void ) . 4 { . 5 int A [2] [2] = {1,2,3,4}; // define an array and a method for shaping some initialization . 6 char b [2] [2] = {{ 'a', 'b'}, { 'c', 'd'}}; // define character arrays and methods of initialization . 7 a [0] [. 1] = a [1] [0] + a [1] [1]; // array element of the same type and the same variable, how to use variables, array elements can be used how 8 }
In addition, there were associative arrays and pointers, you might also get to know the syntactic sugar and other things, but for those of us must learn not 51 single entry, but it does not mean you can not learn, but our current entry 51 MCU can temporarily do not have that knowledge
- Structure: C language structure is also an important knowledge point, with regard to myself, my C language courses are not learned here, I do not know is how kind, but there will be some who do not learn here so I need to say about the structure, if not before the array is able to reflect the characteristics of the type of construction, our structure will be able to be reflected
Structure is composed of several "members" component, in which each member can be a fundamental data type, can also be another type of construction, we now know, it is a new structure type, so we should first it is constructed (we call declare a structure)
. 1 struct structure Name 2 { 3 list of members 4 };Struct keyword indicates that I have to declare a structure, the structure behind the name is the type name structure (this is to emphasize that this is not a variable name, a type name and type name is the same as int)
. 1 struct Grade 2 { . 3 int Chinese; // structure may have elementary data types . 4 int the Math; . 5 int Dictionary Dictionary English; . 6 }; . 7 . 8 struct Student . 9 { 10 int Age; . 11 char name [10]; // can has a structure type 12 is int Number; 13 is char Sex [10]; // can have a variety of different types of data 14 struct Grade data; // member may further be a structure where there is something about the structure definition, we'll We will talk 15 };As an example of this, we can know a structure type (note the type, not a variable) is how to define the members as long as legitimate, and the rest are with you
Then said the definition of the structure variables, and ordinary variables, type name plus the variable name, and they are defined in the following three ways
. 1 struct Student 2 { . 3 char name [10]; . 4 int Number; . 5 } Stu; . 6 // This is the definition of the structure while the defined variable structure variables as Stu . 7 . 8 struct Student . 9 { 10 char name [10] ; . 11 int Number; 12 is }; 13 is struct Student Stu; 14 after // this is the definition of the type of structure, then the structure defined variable, the same variables or Stu 15 16 struct . 17 { 18 is char name [10]; . 19 intNumber; 20 is } Stu; 21 is // no definition of the structure of this type name, the definition of variables of this type can only be defined at the same time the structure defined variable is not defined elsewhereThen we talk about the use of a structure variable, we will use the member operators when accessing a structure variable: "." - "." And ">", which used to structure variables, such as Stu. name is the name the members Stu visit, and we will need if it is a pointer type "->", for example & Stu-> name, because our & Stu Stu is a pointer, which is a structure pointer, so we want to access structure members will need to use the "->" instead, members and the general structure of the variable to use is the same, where you can go to access some information see the specific knowledge. ""
The definition of union and structures are similar, you just need to change the struct union, it is a common, shared body structure and usage is the same, only members of the structure exist simultaneously, while a shared body member There is a one time only, at the time of assignment to a member, the other members are invalid, and this is the difference between a union and a structure
What remains is an enumerated type, although this will be used in microcontrollers, but you do not have to understand is, if you want to know, Internet access to information, then I may also write C language blog entry, wait until then to look also possible
About construction type stop here, and want to use its skilled master, must own up employment