1

I have a class with

class IntFile
{
public:
    int value;
    int *array;
}

And there is my main

int main()
{
    IntFile myfile;

    myfile.array = new int[CAPACITY];
    int number;
    cout << "Enter number of elements: " << endl;
    cin >> number;

    cout << "Enter your numbers: ";
    for ( int i = 0; i < number; i++)
    {
        cin >> myfile.value;
        myfile.array[i] = myfile.value;
    }
    cout << endl;

    int n = sizeof(myfile.array);

    cout << " THE SIZE OF ARRAY IS " << n << endl;



    delete[]myfile.array;

    cout << endl;
    return 0;
}

Shouldn't the sizeof(array) = 4*number of elements in array? Because for me, I'm always getting sizeof(myfile.array) = 4

CAPACITY is global and = 1000;

3
  • 3
    array is a pointer. Commented Oct 15, 2017 at 10:21
  • array is a pointer, so sizeof returns 4 for 32bit applications of 8 for 64bit applications. You could use std::array and call arr.size() function to retrieve the amount of elements it holds. Commented Oct 15, 2017 at 10:45
  • Use std::vector. It has a size function. Commented Oct 15, 2017 at 11:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.