Go Memset-C + + in

Source: Internet
Author: User

http://blog.csdn.net/songuooo/article/details/7819790

1. Required Header Files

C for <memory.h> or <string.h>

<cstring> in C + +

2. Function prototypes

void * memset ( void * ptr, int value, size_t num);

Assign value to num bytes starting with the address PTR, note that each byte in the NUM byte that starts with PTR is assigned value as value.

(1) If PTR points to a char address, value can be any of the character values;

(2) If PTR points to a non-char type, such as an int address, to assign the correct value, value can only be 1 or 0, because 1 and 0 are converted to binary after each bit is the same, set int is 4 bytes, then -1=0xffffffff, 0=0x00000000.

example, assign the correct value correctly:

[CPP]
int a[2];

Memset (A,-1, sizeof a);

The assignment process is as follows:

Because the int is four bytes, the memset is assigned by byte-by-bit, so a[0] or a[1] is actually a four-byte value, which is 0xffffffff=-1.

Example, Error assignment:

[CPP]
int a[2];

Memset (A, 1, sizeof a);

The assignment process is as follows:

The value of a[0] is actually 0x01010101=16843009, so it's not what we expected.

Go Memset-C + + in

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.