peculiar behaviour

ganesh_don's Avatar
Go4Expert Member
1.) #include<stdio.h>
2.) #include<malloc.h>

3.) struct node
4.) {
5.) int val;
6.) struct node *next;
7.) };

8.) typedef struct node *Node;

9.) struct stack
10.) {
11.) Node head;
12.) };

13.) typedef struct stack *Stack;

14.) int main()
15.) {
16.) Stack s;
17.) int val;
18.) s->head=NULL;
19.) return 0;
20.) }

Note: line numbers are provided for easy discussion abt the line

Buddies....This program gives me segmentation fault but when i interchanged line 16 and 17 it worked fine.. I dont know wat actually happened.somebody plzz help me....thanks in advance
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You are not allocating the pointer s and so anything can happen which is out of your control.
0
ganesh_don's Avatar
Go4Expert Member
Thankyou buddy......i have been breaking my head for days.Thanks a lot dude...it worked fine.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by ganesh_don
Thankyou buddy......i have been breaking my head for days.Thanks a lot dude...it worked fine.
My pleasure.