C语言 c - 如何将数组的值分配给c中的另一个数组(制作副本)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13903388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:45:54 来源:igfitidea点击:
How to assign values of array to another array(making copy) in c?
提问by Nakib
I want to copy 2d array and assign it to another.
我想复制二维数组并将其分配给另一个。
In python i will do something like this
在python中我会做这样的事情
grid = [['a','b','c'],['d','e','f'],['g','h','i']]
grid_copy = grid
I want to do same in C.
我想在 C 中做同样的事情。
char grid[3][3] = {{'a','b','c'},{'d','e','f'},{'g','h','i'}};
How do i copy this array to copy_grid ?
我如何将此数组复制到 copy_grid ?
回答by ouah
Use memcpystandard function:
使用memcpy标准功能:
char grid[3][3] = {{'a','b','c'},{'d','e','f'},{'g','h','i'}};
char grid_copy[3][3];
memcpy(grid_copy, grid, sizeof grid_copy);

