Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个现有的向量 x:
float x[4] = {1.0f, 2.0f, 4.0f, 8.0f};
如何生成另一个与 x 完全相同但标量 1.0 在前面位置的向量,从而生成一个 5 元素向量?
也许是这样的:
float y[5]; y[0] = 1.0f; memcpy(&y[1], x, sizeof(x));
memcpy可以为你做:
memcpy
float y[5] = { 1.0f }; memcpy(y + 1, x, sizeof x);