Thread: How to pass a pointer to a function that can change to addr of the pointer?

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    88

    Question How to pass a pointer to a function that can change to addr of the pointer?

    //in this way:

    Code:
    void ChangeAddr( int **b ){
       *b = (int*) malloc( ... );
    }
    
    void main(){
       int *a ;
       ChangeAddr( a );
    }
    // like this??
    // THANK Q>

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well you shouldn't cast the return of malloc. Also you shouldn't use void main()
    But yes that would do it.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Not quite.
    Code:
    ChangeAddr( a ); -> ChangeAddr( &a );
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Heh I was looking at the ChangeAddr function I didn't even notice the call.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    88
    Quote Originally Posted by Thantos
    Well you shouldn't cast the return of malloc. Also you shouldn't use void main()
    But yes that would do it.
    OK, well, now I've understood, FAQ:"The return type of main() must always be an int, this allows a return code to be passed to the invoker."

    and ,i'm sorry, , What is the meaning of cast?

    thx.
    Last edited by L.O.K.; 11-27-2004 at 05:44 PM.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by L.O.K.
    What is the meaning of cast?
    Preceding an expression by a parenthesized type name converts the value of the expression to the named type.

    FAQ > Explanations of... > Casting malloc
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    88
    Quote Originally Posted by Dave_Sinkula
    Preceding an expression by a parenthesized type name converts the value of the expression to the named type.

    FAQ > Explanations of... > Casting malloc

    Oh, thx so much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM