just echoing with examples…
in C, use memcpy, and be careful:
#include <string.h>
#include <stdio.h>
#define SIZE 10 // can't initialize stack-allocated C-style arr with variable size
int main() {
typedef float sample_t;
sample_t a[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
sample_t b[SIZE];
memcpy(b, a, SIZE * sizeof(sample_t));
// change stuff in `a`
for (int i=0; i<SIZE; ++i) {
a[i] = i * 2;
}
// print `b`
for (int i=0; i<10; ++i) {
printf("%f ", b[i]);
}
printf("\n");
}
in C++, prefer std::array (fixed size) or std::vector (mutable size), and built-in copy semantics:
#include <array>
#include <iostream>
constexpr size_t size = 10; // yay, `constexpr` exists
typedef float sample_t;
int main() {
typedef std::array<sample_t, size> arr_t;
arr_t a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
arr_t b;
b = a; // copies
// change stuff in `a`
for (int i=0; i<size; ++i) {
a[i] = i * 2;
}
// print `b`:
for (auto& x: b) {
std::cout << x << " ";
}
std::cout << std::endl;
}