The Gateway to Computer Science Excellence
0 votes
215 views

Consider the C node fragment given below:

Which of the following true about above code if input is given as linked list of n-element in which for each node memory is created in heap area?

A. Compiles successfully but execution may result in dangling pointer.

B. Compiles successfully but execution may result in memory leak problem.

C. It will produce compile time error.

D. Compilation error because p = = NULL not present after free (p) in else part.


I think answer should be C. Because the return type is int node* 

Can someone please confirm.

in Programming by Boss (17.5k points)
edited by | 215 views
+1
yes, dangling pointer and memory leak both not issue here

So, C most relevant
0

It will give Runtime error of type SEGFAULT when the list is empty, and also on the error you point out.

@srestha I think it is currently not in Memory leak, but if we interchange the below two lines in the above code then it will definitely cause Memory leak.

s = NULL

free(s);

memory leak of one node.

0
Don't we need p=NULL in the last part?

Please log in or register to answer this question.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,492 answers
195,439 comments
100,710 users