Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!udel!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Passing pointers to structures Keywords: pointer struct Message-ID: <14903@smoke.brl.mil> Date: 20 Jan 91 08:25:15 GMT References: <1991Jan19.055923.19423@unicorn.cc.wwu.edu> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 27 In article <1991Jan19.055923.19423@unicorn.cc.wwu.edu> n8743196@unicorn.cc.wwu.edu (Jeff Wandling) writes: - struct node { - int key; - }; - foo(h_ptr) - struct node *h_ptr; /* ?? */ - { - h_ptr->key=10; /* anything */ - } - main() - { - struct node *head; - foo(head); OR foo(&head); /* ?? K&R 1, p91 says use '&head' - but this isn't the same. Or is - it? */ - } What you probably wanted to do was: main() { struct node head; /* NOTE: not just a pointer */ foo(&head); /* definitely not the same as foo(head); which would pass the entire structure rather than just a pointer to it */ return 0; /* please return exit status */ }