Please answer all of them. Thank you This and the following questions provide co
ID: 3885999 • Letter: P
Question
Please answer all of them. Thank you
This and the following questions provide code and you have to answer whether or not there is a bug in that code If yes, give the number of the line where the bug is If there are bugs in more than one line or the code is wrong because of a combination of lines, list all these line numbers in increasing order, separated with a comma and with no extra spaces (e.g. 1 If the code is wrong because there is a memory leak (allocated memory was not freed) answer with the word leak If the code is correct (no bug), answer with the word none Example of correct answer formats: 1,5,6,7 one leak Examples of incorrect answer formats 5,6,7,1 (not in increasing order) 1567 (separated by spaces, not by commas) intmem 1 in(änt x) line 1 / line 2 / line 3 return x; void mem_1) i // line 4 // line 5 int x = 10; int * = mem 1 in (x) ; printf("+p = %d ". *p); // line 6 Iine // 7 QUESTION 10 / Allocate dynamic memory, set it to 25, return the pointer to it. int mem 31 line1 // line 2 int *p = 25; print f("p=ed " , return Pi //line 3 +P ); // line 4 Give the line(s) with bugs or noneExplanation / Answer
10)2
11)none
12)4
13)2
Explanations:
10)The memmory needs to be allocated for the pointer.
12)The value 7 should be allocated to the memory p is pointing to. So the correct answer would be *p =7;
13)The memory should be allocated as:
p = (struct point *)malloc(sizeof(struct point));
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.