"Entity class" in C Language -- struct

Source: Internet
Author: User

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:

  1. # Include <string. h>
  2. Struct vote {
  3. Char name [16];
  4. Int num;
  5. };
  6. Struct vote STU [4] = {"Zhao", 0 },{ "Qian", 0 },{ "sun", 0 },{ "Li ", 0 }};
  7. Main (){
  8. Int I, J;
  9. Char V [16];
  10. For (I = 0; I <10; I ++)
  11. {
  12. Scanf ("% s", V );
  13. For (j = 0; j <4; j ++ ){
  14. If (strcmp (v, STU [J]. Name) = 0) STU [J]. Num ++;
  15. }
  16. }
  17. For (j = 0; j <4; j ++ ){
  18. Printf ("Name: % s, num: % d/N", STU [J]. Name, STU [J]. Num );
  19. }
  20. }

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 ".

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.