0
Is it proper procedure to declare the size of array with function arguement
Hi friend, I have one doubt void function(char* a, int len) { int arr[len]; . . . } Is this proper procedure, declaring the size of array with the function arguement (formal parameter). I did like that in my code, it is working . If I initialize array to zero , it is getting error. Is this a proper programming...? if possible please explain. Thank you
2 Respuestas
+ 5
It should work,
Can you saw us code that we can see what problem is there?
+ 1
normally you do not want to give user control over the size of the array just like that. arrays are fixed. if you need something dynamic use vectors.
you could add an if statement inside the function to restrict the size to certain limits.
or restrict how that parameter is initialized before being passed to the function.
in C you would have to use malloc()
*it depends on where that int len is coming from.