I am new to C and C++, please help me in getting the required solution. I have used memcpy to copy the contents of 'array' to 'arr'. But since the size of 'arr' is 10, it appends 0 to the remaining elements. How can I truncate the 'arr' to size 5.
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
uint8_t array[5] = {1,2,3,4,5};
uint8_t arr[10] = {0};
memcpy( arr, array, 5);
for (auto e: arr){
cout << e << " ";
}
return 0;
}
Output for the above code: 1 2 3 4 5 0 0 0 0 0
required output : 1 2 3 4 5