C + + array processing related functions (memcpy/memset, etc.)

Source: Internet
Author: User

Header file: string.h

void *memcpy (void *dest, const void *SRC, size_t n);
Function: Copies n bytes from the beginning of the memory address referred to by the source SRC to the starting position of the memory address referred to by the target dest

void *memset (void *s, int ch, size_t n);
function: Replace n bytes (typedef unsigned int size_t) with the current position in s with ch and return S.
Memset: The function is to populate a block of memory with a given value, which is the fastest way to clear 0 operations on a larger struct or array

#include <iostream> #include <string.h>using namespace Std;int main () {    int array_a[12] = { 23,45,6,7,4776,834,99954};    int array_b[12];    memset (Array_b,-1, sizeof (ARRAY_A)); Initializes the elements of array B to-1    memcpy (array_b, array_a+1, sizeof (int) *6);    for (int i=0;i<12;i++) {        printf ("%d", Array_b[i]);    }    return 0;}

C + + array processing related functions (memcpy/memset, etc.)

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.