Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   peculiar behaviour (http://www.go4expert.com/forums/peculiar-behaviour-t3356/)

ganesh_don 12Mar2007 09:41

peculiar behaviour
 
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

shabbir 12Mar2007 10:32

Re: peculiar behaviour
 
You are not allocating the pointer s and so anything can happen which is out of your control.

ganesh_don 12Mar2007 16:49

Re: peculiar behaviour
 
Thankyou buddy......i have been breaking my head for days.Thanks a lot dude...it worked fine.

shabbir 12Mar2007 17:09

Re: peculiar behaviour
 
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.


All times are GMT +5.5. The time now is 11:26.