Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the size of an array in C?

Tags:

People also ask

Can you modify the size of an array?

The simple answer is that you cannot do this. Once an array has been created, its size cannot be changed. Instead, an array can only be "resized" by creating a new array with the appropriate size and copying the elements from the existing array to the new one.

Can we change the size of an array at run time in C?

No. In an array declaration, the size must be known at compile time. You can�t specify a size that�s known only at runtime.

How do you set the size of an array?

If you want to change the size, you need to create a new array of the desired size, and then copy elements from the old array to the new array, and use the new array. In our example, arr can only hold int values. Arrays can hold primitive values, unlike ArrayList, which can only hold object values.


I am experimenting a little bit with gamestudio. I am now making a shooter game. I have an array with the pointers to the enemies. When an enemy is killed, I want to remove him from the list. And I also want to be able to create new enemies.

Gamestudio uses a scripting language named lite-C. It has the same syntax as C and on the website they say, that it can be compiled with any C compiler. It is pure C, no C++ or anything else.

I am new to C. I normally program in .NET languages and some scripting languages.