Consider this simple program in Python:
n=int(input("enter your lower limit"))
m=int(input("enter your higher limit"))
list=[]
x=n
while x<=m:
if (x%2==0):
list.append(x)
x+=1
print("the even numbers in your range are:",end="")
print(len(list))
Here I can initially declare the elements of list to nothing and keep inserting a result in it, the range of which completely depends on user. And then I can check the length of that list therefore how many elements fulfilled my conditions between the user's range. So it gets easy in Python!
But in C, I must initially declare the number of elements of an array! I can declare it to a random large number and then keep inserting a result. And then find out the ultimate result (how many elements fulfilled my conditions between the user's range) by checking how many elements are there before the character \0. But it still wastes a lot of memory and keeps garbage in the unused elements which may cause problem in bigger programs!
Well! I know a little about malloc(). But I have to declare the size here too! Though I can free the memory later which reduces pressure in bigger programs but I really want to know if there exists any straightforward process in C like Python?
realloc, and you can implement linked-lists or other such "high-level" data structures. But that's about it, nothing in standard C like a vector.m,nand that you're going to append in 50% of the cases so it's trivial to compute how big the list needs to be in advance. Why not just do that for malloc or array size? Even if you don't know that you're going to append for 50% you can still compute an upper bound on the number of insertions.