I have created node
structure and created pointer of the same inside main
but didn't allocated memory for node structure
: struct node * first
or struct node * second
(which was supposed to be allocated dynamically- malloc
/calloc
). Instead, I am able to access data(or memory for structure)
#include<stdio.h>
struct node{
int data;
struct node *next;
};
void Traverse(struct node * head){
while (head!=NULL)
{
printf("Data:%d\n", head->data);
head=head->next;
}
}
int main()
{
struct node * first;
struct node * second;
first->data=33;
first->next=second;
second->data=45;
second->next=NULL;
Traverse(first);
return 0;
}
Currently I am running this code in VS Code so is this the VS Code which is doing it automatically or something else is happening internally?