Is it possible to declare a dynamic array without using malloc,calloc,and pointer.

Questions by sudhanshu shekhar   answers by sudhanshu shekhar

Showing Answers 1 - 12 of 12 Answers

santhosh

  • Dec 23rd, 2006
 

it is possible, but you may lose some datas or you may consume more space to store even a smaller size datas unknowingly. i.e a[' '];

  Was this answer useful?  Yes

Deepam

  • Jan 3rd, 2007
 

No ,its not possible to have a dynamic array without using calloc,malloc or without ptr.... Why u want to know abt it? but u can achieve a array without specifying size say arr[]; but its not efficient as when u use this array..more space will be allocated and if the data stored is less...naturally more space remain unused so loss.Its not the efficent way of doing this..to overcome this only they developed a concept called Dynamic memory using calloc,malloc,new ,delete...

  Was this answer useful?  Yes

C99 introduced the concept of a Variable Length Array (VLA), where the array size doesn't have to be known until runtime:

size_t elements=10;
int arr[elements];

They act pretty much like regular, statically-allocated arrays, with a few restrictions (you cannot initialize them like regular arrays, for example, and they cannot be declared at file scope).  Like regular arrays, their lifetime is limited to their enclosing scope (as opposed to objects allocated with malloc() or calloc()). 

They come in handy when you don't know ahead of time how much memory you will need for a specific operation within a function, but don't want to deal with memory management operations (malloc() and free()). 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions