i get this message in .net :
Error 1 error C2540: non-constant expression as array bound \documents\visual studio 2010\projects\test3\test3\test3.cpp 18 1 Test3
Error 2 error C2440: 'initializing' : cannot convert from 'long (*)' to 'long *' \documents\visual studio 2010\projects\test3\test3\test3.cpp 18 1 Test3
Error 3 error C2109: subscript requires array or pointer type \documents\visual studio 2010\projects\test3\test3\test3.cpp 24 1 Test3
// Test3.cpp : Defines the entry point for the console application.
long int bin(int n,int k);
int _tmain(int argc, _TCHAR* argv)
std::cout << " example : \n" << bin(10,5) << "\n" ;
long int bin(int n , int k)
// long int b[n][k];
long int *b = new long int[n][k];
for (j=0;j<i;j++) // For (j=0;j< min(I,k);j++)
if(j==0 || j==i)
Last edited on
Your code appears to have nothing to do with the subject of the thread or the image you linked, other than having variables named n and k.
You don't want a two dimensional array here if the subject is accurate. What are you trying to do exactly? Describe the algorithm you're attempting to implement in bin.
That's not how you dynamically allocate 2-dimensional arrays.
I'm sure a suitable Google search will find you some examples of how to do it. My advice would be to stop using C-style arrays, and start using STL vectors instead.
Last edited on
it's generally a bad code habit for a c++ beginner declare a 2 dimensional array with pointer. It's so much old style :)
However if you want to do it no matter what, you should declare a long int double pointer
long int **b
otherwise you are declaring a one dimensional array.