Thread: pointers

  1. #1
    Unregistered
    Guest

    pointers

    hello im trying to figure out linked lists and pointers in the following example can someone please explane the spacing and location of the * and what the spacing and location do to the prog
    struct cmdlist * add_command(struct node* head, struct node* tail){
    struct cmdlist *commandlist=(struct cmdlist*)malloc(sizeof(struct cmdlist*));

    also
    what is the dif between node* head
    and node *head

    thanks in advance
    confused with pointers

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >struct cmdlist * add_command(struct node* head, struct node* tail){
    This is a function called add_command that takes a pointer to the first and last nodes of a linked list and returns a pointer to a structure, probably also a node of a linked list.

    >struct cmdlist *commandlist=(struct cmdlist*)malloc(sizeof(struct cmdlist*));
    This is a pointer variable called commandlist of type struct cmdlist. It is being allocated memory immediately upon creation.
    (struct cmdlist*)malloc(sizeof(struct cmdlist*));
    This is simply allocating memory big enough for a cmdlist pointer, but in C malloc doesn't have to be and shouldn't be cast.

    >what is the dif between node* head
    >and node *head
    Programmer preference

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  2. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM