Error[8]: Undefined offset: 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

memcpy函数用法 memcpy指的是C和C++使用的内存拷贝函数,函数原型为void *memcpy(void *destin, void *source, unsigned n);函数的功能是从源内存地址的起始位置开始拷贝若干个字节到目标内存地址中,即从源source中拷贝n个字节到目标destin中。

函数原型

void *memcpy(void *destin, void *source, unsigned n);

参数

destin-- 指向用于存储复制内容的目标数组,类型强制转换为 void* 指针。

source-- 指向要复制的数据源,类型强制转换为 void* 指针。

n-- 要被复制的字节数。

返回值

该函数返回一个指向目标存储区destin的指针。

功能

从源source所指的内存地址的起始位置开始拷贝n个字节到目标destin所指的内存地址的起始位置中。 [2]

所需头文件

C语言:#include<string.h>

C++:#include<cstring>

示例:

作用:将s中的字符串复制到字符数组d中。

//memcpy.c
#include <stdio.h>
#include <string.h>
int main()
{
    char* s="GoldenGlobalView";
    char d[20];
    clrscr();
    memcpy(d,s,(strlen(s)+1));        //+1 是为了将字符串后面的'[+++]'字符结尾符放进来,去掉+1可能出现乱码
    printf("%s",d);
    getchar();
    return 0;
}

输出结果:Golden Global View

以上就是memcpy函数用法的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

memcpy函数用法_C_内存溢出

memcpy函数用法

memcpy函数用法,第1张

memcpy函数用法 memcpy指的是C和C++使用的内存拷贝函数,函数原型为void *memcpy(void *destin, void *source, unsigned n);函数的功能是从源内存地址的起始位置开始拷贝若干个字节到目标内存地址中,即从源source中拷贝n个字节到目标destin中。

函数原型

void *memcpy(void *destin, void *source, unsigned n);

参数

destin-- 指向用于存储复制内容的目标数组,类型强制转换为 void* 指针。

source-- 指向要复制的数据源,类型强制转换为 void* 指针。

n-- 要被复制的字节数。

返回值

该函数返回一个指向目标存储区destin的指针。

功能

从源source所指的内存地址的起始位置开始拷贝n个字节到目标destin所指的内存地址的起始位置中。 [2]

所需头文件

C语言:#include<string.h>

C++:#include<cstring>

示例:

作用:将s中的字符串复制到字符数组d中。

//memcpy.c
#include <stdio.h>
#include <string.h>
int main()
{
    char* s="GoldenGlobalView";
    char d[20];
    clrscr();
    memcpy(d,s,(strlen(s)+1));        //+1 是为了将字符串后面的''字符结尾符放进来,去掉+1可能出现乱码
    printf("%s",d);
    getchar();
    return 0;
}

输出结果:Golden Global View

以上就是memcpy函数用法的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/686334.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-21
下一篇 2022-04-21

发表评论

登录后才能评论

评论列表(0条)

保存