Answer the question
In order to leave comments, you need to log in
How to create and use a dynamic array?
How to create and use a dynamic array in C?
It’s just that I don’t know in advance how many values will be in it, is it for this that dynamic ones are used?
Answer the question
In order to leave comments, you need to log in
Let N be the number of elements in the array:
#include "stdlib.h"
...
int * arr = (int*)malloc(sizeof(int) * N);
...
for(int i = 0; i < N; ++i)
printf("%d ", arr[i]);
printf("\n");
free(arr);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question