I want to read from user input some numbers and then display them 5 on each line. My code is like this:
#include <iostream>
using namespace std;
const int INPUT_SIZE = 7;
void printValues(int *b) {
int counter = 0;
while (counter < INPUT_SIZE) {
cout << *(b+counter) << " ";
if ((counter + 1) % 5 == 0 && counter>0) {
cout << endl;
}
counter++;
}
cout << endl;
system("pause");
}
int * readValues() {
int b[INPUT_SIZE];
for (int i = 0; i < INPUT_SIZE; i++) {
cout << "Enter element on position: " << i << ": ";
cin >> b[i];
}
return b;
}
int main() {
int* b;
b = readValues();
printValues(b);
return 0;
}
However, when I try to print them, I get some weird numbers which I think are memory locations. How do I print an array and also how do I write a function that returns an array? I have little experience with pointers, as I only coded in Java so far. Help much appreciated.