Why can't memset initialize array elements to 1?

Source: Internet
Author: User

Prototype: extern void *memset (void *buffer, int c, int count);

Function: Sets the first count bytes of the memory area indicated by buffer to character C.

Contains header files:<string.h>

Note that this function is a string function, so be sure to include the string header file.

How to use:

int A[50];

memset (A,0,sizeof (a));

That way, all the values in array A are assigned to 0, and sizeof is a unary operator that gets the byte size of array A.

It is also important to note that the Memset function is populated by byte bytes, so A is generally char * type . For other types of a, the values that can be populated are two, 0, and -1. Since the computer uses twos complement to denote numbers, the 0 and twos complement are full 0,-1 's twos complement of 1.

The memset is a byte-by-byte setting that sets each byte of an int to 1, which is 0x01010101, and the decimal is 16843009.

What do I do to initialize 1?

To set the int array to 1, use the For loop to set the line. Or enumerations can also be

Why can't memset initialize array elements to 1?

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.