1,2 and 3 is wrong. 2 only is also wrong. Please read the question carefully and
ID: 3721932 • Letter: 1
Question
1,2 and 3 is wrong. 2 only is also wrong. Please read the question carefully and answer the question.
Question 6 1 pts Consider the following 3 code fragments 1) int *ptrmalloc (sizeof (int)*3) ptr[0] = 0; ptr[1] = 0; ptr [2] = 0; 2) int *ptr = calloc (3, if (ptr == NULL){ sizeof (int)); printf("Unable to allocate memory.In") exit(1) 3) int *ptrcalloc(1, sizeof (int)) if (ptr== NULL){ printf( "Unable to allocate memory. "); exit (1) 3*sizeof (int)); ptr = realloc ( ptr, if (ptr == NULL){ printf("Unable to allocate memory. "); exit (1) Dynamic allocation of an integer array of size 3 with elements initialized to O is safely done in code fragment(s) 2 only 1,2 and 3 1 only 1 and 2 2 and 3Explanation / Answer
The option 2 and 3 is correct.
Because in these code segments ptr is checked if it is not NULL and this check has to be there
before the usage of ptr.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.