I am trying to pass an array in a function and then printing it out the values found inside the array.
this is what I have
numbers.cpp
#include <iostream>
#include <string>
#include "numbers.h"
int * numbers::printNumbers() {
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
arrayOne[j] =i;
}
}
return arrayOne;
}
numbers.h
#ifndef try_numbers_h
#define try_numbers_h
#include <iostream>
#include <string>
class numbers {
public:
int * printNumbers();
private:
int arrayOne[4];
};
#endif
main.cpp
#include <iostream>
#include <string>
#include "numbers.h"
int main () {
numbers printNum;
int * p;
p = printNum.printNumbers();
}
the codes shown above, run successfully
but my output is returning some weird memory address
output
0x7fff5fbff8e0
by right it should output
expect output
0
1
2
3
std::vectorinstead of an array.