What is the difference between
int size; int *arr; scanf("%i", &size); arr = malloc(size * sizeof(*arr));and
int size; scanf("%i", &size); int arr[size];When I want to allocate memory for 2 big numbers i would use the following code:
unsigned long *big_nums; big_nums = malloc(2 * sizeof(*big_nums));I would access the first big bumber using big_nums[0] an the seond one with big_nums[1]. Let's say unsigned long is 4 bytes big, then the code would allocate 2 * 4 = 8 bytes. Let's say I do something like this:
unsigned long *big_nums; big_nums = malloc(7);
Using big_nums[0] is clear for me, but how about big_nums[1]? Will it cause some kind of segmentation fault error or what?
big_nums = malloc(2 * sizeof(big_nums));should be... = malloc(2 * sizeof big_nums[0])