So, I am learning C right now, and wanted some clarification on some things.
I've learned that if we wanted to create a dynamic arrays we could use the following line of code:
int *arr = malloc(10 * sizeof(int));
I understand that, in this case, arr is a pointer being allocated the equivalent of an array of 10 ints in terms of bytes. I also understand that you can treat arr as an array (from arr[0] to arr[9].
Does that mean all pointers that are allocated memory can be treated as an array?
Like could this be treated as an array?
int *single = malloc(sizeof(int));
Or could this be treated as an array?
int *half = malloc(sizeof(int) * 1.5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With