Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Which of the following memory violations (if any) does the following function have? 1: int fun(int k) { 2: int * tmp 3: tmp =
Which of the following memory violations (if any) does the following function have?
1: int fun(int k) { 2: int * tmp 3: tmp = (int *) calloc(k, sizeof(int)); 4: for (int i = 0; i < k; i++) 5: scanf("%d", &tmp[i]) 6: realloc(tmp, sizeof(int) * k * 2); 7: int ans = tmp[k-1]; 8: free(tmp); 9: return ans 10:}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started