Question: RECURSION C PROGRAMMING If you compile following code using the command line given in the example, there is no error. _____________________________________________________________________________ gcc main.c -o ll
RECURSION C PROGRAMMING
If you compile following code using the command line given in the example, there is no error.
_____________________________________________________________________________
gcc main.c -o ll -Wall
_____________________________________________________________________________
However, if you use g++ rather than gcc, you would get the following error:
_____________________________________________________________________________
g++ main.c -o ll -Wall
main.c: In function 'NODE* DuplicateLinkedList(const NODE*)':
main.c:28:19: error: invalid conversion from 'void*' to 'NODE* {aka node*}' [-fpermissive]
pDupHead=malloc(sizeof(NODE));
~~~~~~^~~~~~~~~~~~~~
_____________________________________________________________________________
Both gcc and g++ are GNU compilers. Explain what is going on here...
// compiled with gcc: // gcc main.c -o ll -Wall // // output of: ./ll // 0 // 1 // 2 // ===================================================================== #include#include #include struct node{ int nValue; struct node *pNextNode; }; typedef struct node NODE; NODE *DuplicateLinkedList(const NODE *pList){ NODE *pDupHead=NULL; NODE *pN=NULL; if(pList!=NULL) { pN=DuplicateLinkedList(pList->pNextNode); pDupHead=malloc(sizeof(NODE)); pDupHead->nValue=pList->nValue; pDupHead->pNextNode=pN; } return(pDupHead); } // ===================================================================== int main(void){ NODE N0, N1, N2; NODE *pN=NULL; N0.nValue=0; N0.pNextNode=&N1; N1.nValue=1; N1.pNextNode=&N2; N2.nValue=2; N2.pNextNode=NULL; pN=DuplicateLinkedList(&N0); while(pN!=NULL) { printf("%d ", pN->nValue); pN=pN->pNextNode; } return(0); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
