I'm trying to create a structure which has an integer and a pointer to the same type. So I created a structure of that type but I seem to be printing wrong values.
My ideal output should be
but I'm getting
I can't figure out why this is happening, please help
Code:
#include <stdio.h>
#include <string.h>
#define max 20
struct node{
int i;
struct node *next;
};
void print(struct node*);
int main(){
struct node* b= (struct node*) malloc(sizeof(struct node));
b[0].i = 1;
b[0].next = NULL;
b[1].i = 2;
b[1].next = NULL;
struct node *c = (struct node*) malloc(sizeof(struct node));
c[0].i = 3;
c[0].next = NULL;
c[1].i = 4;
c[1].next = NULL;
b[0].next = c;
//print(b);
printf("%d %d\n",b[0].i,b[1].i);
return 1;
}
Code:
1 2
Code:
1 3
Comment