return pointer of structure

Status
Not open for further replies.

jab99407

Member
I do not understand working of function in the given code. This is a sample function that will be in the linked list. I know only function take data and return pointer

Is it a useful function that adds a new node in the list?

Code:
#include<stdio.h>
#include<stdlib.h>

struct Node{
  int data;
  struct Node *next;
};

struct Node * New_Node( int data){
 
  struct Node *p = malloc(sizeof(*p));
  p->data = data;
  p->next = NULL;
  return p;
}

int main ()
{
    struct Node * pS1;
    struct Node * pS2;

    pS1 = newNode(100);
    pS2 = newNode(456);
    return 0;
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…