Thread: pointer functions

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    115

    pointer functions

    when do you use a declartion or a function which has a pointer out the front.
    i.e

    *function( int *, int n ) ?

    Why cant you just use function( int *, int n )?

    ive seen a few of these *functions in many of the string functions located in the string.h

    when else can u use this notation and why?

    cheers
    there are only 10 people in the world, those who know binary and those who dont

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not sure I exactly know what you're asking. Do you mean:

    char *myfunction( void );

    Why is there a * at the front? If so, that means that that function is returning a pointer rather than void or by value.

    A good example of this is 'malloc'. Malloc locates a block of memory for you, and gives you an address to it. Then you use it how you need.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >when else can u use this notation and why?
    It refers to the return value of the function:
    Code:
    int foo(void); /* Returns an int */
    int *bar(void); /* Returns a pointer to int */
    If it helps you to remember, you can also place the * just after the type instead of just before the identifier:
    Code:
    int* bar(void);
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  3. Replies: 11
    Last Post: 08-28-2008, 04:10 AM
  4. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM
  5. Replies: 2
    Last Post: 11-22-2001, 12:22 PM