Computer Science, asked by worldmando6, 7 hours ago

Question 1: (8 marks)
Draw the Memory Layout of the following C Program. (Hint: Show the content of all the parts of its corresponding process in the memory)

// Program to calculate the sum of n numbers entered by the user

#include
#include

int sum=0, n;

int main()
{
int i;
int *ptr;

printf("Enter number of elements: ");
scanf("%d", &n);

ptr = (int*) malloc(n * sizeof(int));

// if memory cannot be allocated
if(ptr == NULL)
{
printf("Error! memory not allocated.");
exit(0);
}

printf("Enter elements: ");
for(i = 0; i < n; ++i)
{
scanf("%d", ptr + i);
sum += *(ptr + i);
}

printf("Sum = %d", sum);

// deallocating the memory
free(ptr);

return 0;
}

Answers

Answered by 211385adhithyan
0

Answer:

ndbdbdbfvrbr tndvtvtmvtmyktf

Explanation:

ndndndndmfbfmdbnfkfbcmcbfmf

Similar questions