This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Strange thing with static Array!


Hello dear GCC staff

I have strange thing with my C++ code.

as I knew and learned that we can't compile a dynamic size with a
static array at compile time

but my code below can be compiled and I can change the size every time
I run the code

also it is working at run time!!

thank you very much




################# Code #################

#include <iostream>
using namespace std;

int main()
{

        int array_size;

        cout << "Enter the array size: ";
        cin >> array_size;

        int ali[array_size];

        for(int i = 0; i < array_size; i++)
                ali[i] = 0;

        for(int i = 0; i < array_size; i++)
                cout << ali[i] << "   ";
        cout << endl;

        return 0;
}

################# End of The Code #################


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]