Since you've just edited the question, I suppose you're still looking for an answer. The ground has been pretty well covered in comments , but I'll have a go at formalizing.
It is important to understand that although they have similarities in structure and syntax, C arrays and Python lists are not equivalent. In particular,
- C arrays have fixed number of elements, whereas Python lists have dynamic number of elements
- C arrays have elements that are all the same type, whereas Python lists can have elements of different types
- C arrays do not contain any kind of metadata -- their representations consist strictly of the representations of their elements
So, with that in mind,
Is there any way that I can add elements to an array without specifying a position in C, Is there any method similar to the append method in python, in C language?
No. Strictly speaking, the question does not even make sense, because C arrays have fixed length. Code such as your example draws a distinction between array elements that contain valid data and those that do not, but that is something layered on top of the array. The array itself has no inherent sense of or representation for a distinction between valid and invalid elements.
But of course, if you want something like that then you can implement it yourself, as indeed CPython does. You can even implement a structure that does not impose an inherent limit on the number of elements. The data structure itself might look something like this:
struct int_list {
int *elements;
size_t size;
size_t capacity;
};
To go with that, you would want to add functions for initializing such objects, adding and removing elements, and anything else you want to do with them. C's array-indexing operator will not work with them.
Note also that if you were asking about C++ instead of C then there would be a simpler answer: use a std::vector
instead of a C-style array.