Memset and sizeof ()

Source: Internet
Author: User
Memset has many usage network resources. The following is my personal experience. ========================================================== ======================================

Memset usage

(The third parameter is the number of bytes) 1. For the character array char a [10]; memset (A, 'A', sizeof (a); 2, for integer arrays int A [10]; memset (A, 0, sizeof (INT) * 10); integer Arrays can only be filled with 0 and-1, the double type can only be filled with 0. if memset (A, 0, sizeof (a) is used according to the double type principle of binary storage, it can be safely executed in vs2005, but the runtime error is reported on OJ. //Reserves the right to final interpretation. If memset (A,) is used, the array is garbled because int requires four bytes to represent a decimal number. Only two half ================================================= ============================================================ comparison of sizeof (INT) the relationship between sizeof (A) and sizeof (INT) is the number of bytes to obtain the type. If the operating system is 32 bits, the result is 4, and sizeof () obtains the number of bytes of; ========================================================== ====================================== sizeof () perform the following operations on struct and classes: struct def {int data; double data1; char data2 ;}; total number of bytes: int M = 4 + 4 + 8 + 1 = 17,17> sizeof (double), add to the multiples of sizeof (double) because according to the VC alignment rule, int is obtained and then double, add the total number to 8. Because m> sizeof (double), increase MZ to a multiple of sizeof (double. This sizeof (double) is the maximum number of bytes in the structure. ========================================================== ============================================================== Today I made a simple after the DP question, I found that I don't know much about memset and sizeof. Supplement the basics. ========================================================== ======================================== Reference materials: bytes ~~

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.