I have this piece of code that I want to write elements of an array with. However, nothing gets written on the standard output. When I try to return a value in an array everything is fine, and the for loop is also not the problem. Any ideas?
#include <iostream>
using namespace std;
int write(unsigned char* a, int n) {
for (int i=0; i<n; i++) {
std::cout << a[i] << '\n';
}
return -1;
}
int main() {
int n;
std::cin >> n;
unsigned char* a = new unsigned char[n];
for (int i=0; i<n; i++) {
int x;
std::cin >> x;
a[i] = (unsigned char)x;
}
std::cout << write(a,n) << '\n';
delete[] a;
return 0;
}