When using an object-oriented programming language, we like to write the corresponding entity classes for processing database data, so that the fields in the data table correspond to the attributes in the Entity class one by one, so as to facilitate program operations.
Today, when I read the structure in C language, I suddenly realized that this idea was available early in the morning. For example, the structure in C language, I think it is the earliest entity.
Here is a small example:
- # Include <string. h>
- Struct vote {
- Char name [16];
- Int num;
- };
- Struct vote STU [4] = {"Zhao", 0 },{ "Qian", 0 },{ "sun", 0 },{ "Li ", 0 }};
- Main (){
- Int I, J;
- Char V [16];
- For (I = 0; I <10; I ++)
- {
- Scanf ("% s", V );
- For (j = 0; j <4; j ++ ){
- If (strcmp (v, STU [J]. Name) = 0) STU [J]. Num ++;
- }
- }
- For (j = 0; j <4; j ++ ){
- Printf ("Name: % s, num: % d/N", STU [J]. Name, STU [J]. Num );
- }
- }
A small voting program, using struct, can easily and easily write programs. If arrays are used, it is convenient and difficult to understand, because related data must be stored in irrelevant data and cannot be referenced ".
On the other hand, the rest of the struct are skipped today, and there is still a little pointer knowledge in front of it. However, looking at pointer operations is too confusing for the brain. Think about it. In fact, it is also possible to jump to read something that is easy to understand first. Maybe from the progress of learning, this will be more efficient. The structure concept is more similar to "Basic ".