zoukankan      html  css  js  c++  java
  • memcpy()

    memcpy() is used to copy a block of memory from a location to another. It is declared in string.h

    Below is a sample C program to show working of memcpy().

    /* A C program to demonstrate working of memcpy */
    #include <stdio.h> 
    #include <string.h> 
    
    int main () 
    { 
    char str1[] = "Geeks"; 
    char str2[] = "Quiz"; 
    
    puts("str1 before memcpy "); 
    puts(str1); 
    
    /* Copies contents of str2 to sr1 */
    memcpy (str1, str2, sizeof(str2)); 
    
    puts("\nstr1 after memcpy "); 
    puts(str1); 
    
    return 0; 
    } 

    Output:

    str1 before memcpy 
    Geeks
    
    str1 after memcpy 
    Quiz

    Notes:
    1) memcpy() doesn’t check for overflow or \0
    2) memcpy() leads to problems when source and destination addresses overlap.

    memmove() is another library function that handles overlapping well.

  • 相关阅读:
    VS快捷键
    IIS部署WCF
    WLAN的优点
    局域网与WAN比较
    局域网拓扑结构
    局域网协议
    局域网介绍
    wifi主要特性
    wifi发展前景
    Wi-Fi与WAPI主要区别
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/12810298.html
Copyright © 2011-2022 走看看