How can I copy a part of an array to another array in C++?

前端 未结 5 1612
执笔经年
执笔经年 2021-02-05 10:07

This is the same question asked in C# but i need for C++

How can I copy a part of an array to another array?

Consider I\'m having

    int[] a = {         


        
5条回答
  •  深忆病人
    2021-02-05 11:01

    For simple C-style arrays you can use memcpy:

    memcpy(b, &a[1], sizeof(int) * 3);
    

    This line copies sizeof(int) * 3 bytes (i.e. 12 bytes) from index 1 of a, with b as a destination.

提交回复
热议问题