So inside of the first loop, we intend to record new inputs to new memory locations if so why we didn't put an asterisk or ampersand to total_sum + limit_reaching
?
My second question is why there's an * in sum += *(total_sum + counter);
but not an &?
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int size_of_sum;
printf("Enter total amount of numbers you want to sum up : ");
scanf("%d", &size_of_sum);
int total_sum;
total_sum = (int*) malloc (size_of_sum * sizeof(int));
for(int limit_reaching = 0; limit_reaching < size_of_sum; limit_reaching++)
{
printf("Enter a number : ");
scanf("%d", total_sum + limit_reaching);
}
int sum = 0;
for(int counter = 0; counter < size_of_sum; counter++)
{
sum += *(total_sum + counter);
}
printf("Sum : %d\n", sum);
free(total_sum);
}
I want to learn what are the roles of * in this code.