Unfortunately, that's not technically allowed by many compilers because a and b are not constants. Since they are not constants, they are not known and the array can't be allocated at compile time. I hear it's technically legal under newer versions of the standards, but not every compiler supports the newer standards yet.

@OP:
I think what you have will work on a compiler that follows the new standard, but I'm not sure. I do know though that your array needs to be declared as a pointer to pointer ("double pointer"), not a ("single") pointer.

To have a truly reliable (portable) implementation though, it's better to explicitly use dynamic allocation. To do so, you declare a "double pointer" to a dataType. Then you allocate to that "double pointer" a 1-dimensional array of "single" pointers to the same dataType. Then you allocate to each "single" pointer within the array a 1-dimensional array of that dataType (actual objects/instances, not pointers). Something like this:

I hear it's technically legal under newer standards, but not every compiler supports the newer standards yet.

Not in C++. The current C standard (C99) supports variable length arrays, but they're an abomination and shouldn't be used. C++ doesn't support variable length arrays in any form because the standard library handles all but the most niche of VLA use cases.

To have a truly reliable (portable) implementation, it's better to explicitly use dynamic allocation.

Or implicitly use dynamic allocation with std::vector. You're doing the same thing with fewer features and a greater chance of implementation bugs.

Not in C++. The current C standard (C99) supports variable length arrays, but they're an abomination and shouldn't be used. C++ doesn't support variable length arrays in any form because the standard library handles all but the most niche of VLA use cases.

Or implicitly use dynamic allocation with std::vector. You're doing the same thing with fewer features and a greater chance of implementation bugs.

I kind-of get the impression this is a dynamic-allocation-related assignment, but I bow to your wisdom: :P :)

Or implicitly use dynamic allocation with std::vector. You're doing the same thing with fewer features and a greater chance of implementation bugs.

So can you please explain how to use this std::vector?

It's not obviously homework, but even if it were, we would be doing the student a disservice by not mentioning the better alternative for future projects.

Well off-course not, this is not a homework. Well for some reason, i have been asked to use constant size for arrays, but i believe there is always a way around. So i am on to it. Just learned how to make it work for 1D array. Not for 2D, second subscript is the problem.

I think what you have will work on a compiler that follows the new standard, but I'm not sure. I do know though that your array needs to be declared as a pointer to pointer ("double pointer"), not a ("single") pointer.

Well off-course not, this is not a homework. Well for some reason, i have been asked to use constant size for arrays, but i believe there is always a way around. So i am on to it. Just learned how to make it work for 1D array. Not for 2D, second subscript is the problem.

Well i am using VC++ 2010 Express Edition...

That still follows an older standard. The code that I posted earlier was written on VC++ 2008.

The only real difference is in the constructor where you need to build up both dimensions. This is the proper way to do it if you already know the sizes, but you can grow the vector dynamically as you go if necessary, that's where the real power lies:

The only real difference is in the constructor where you need to build up both dimensions. This is the proper way to do it if you already know the sizes, but you can grow the vector dynamically as you go if necessary, that's where the real power lies:

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...