Thread: Confused about use of pointers in functions

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    31

    Confused about use of pointers in functions

    If I have the following example

    Code:
    char_t* pbuffer;
    
    pbuffer = (char_t*)malloc(10);
    
    functionTest(pbuffer);
    functionTest is as below

    Code:
    void functionTest(char_t* pbuffer)
    {
       char_t   cbuffer[10];
       memcpy(pbuffer, cbuffer,10);
    }
    my question is for the memcpy function, is it correct that i pass just the pbuffer in?

    or do i pass *pbuffer?

    My interpretation is that i should pass only "pbuffer" in as it is already a pointer itself.

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Yes, you would just pass the pointer. Second, do not cast the return of malloc: Casting Malloc - FAQ.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Pointers
    By JoshD75 in forum C Programming
    Replies: 7
    Last Post: 03-28-2011, 09:43 PM
  2. Confused about writing functions
    By chickenlittle in forum C++ Programming
    Replies: 5
    Last Post: 11-27-2010, 11:52 PM
  3. Still confused with pointers
    By desmond5 in forum C Programming
    Replies: 8
    Last Post: 02-23-2008, 09:32 PM
  4. confused with pointers
    By Mahdi123 in forum C Programming
    Replies: 2
    Last Post: 04-25-2007, 01:08 PM
  5. Very confused with pointers
    By killerasp in forum C++ Programming
    Replies: 5
    Last Post: 01-30-2002, 06:44 PM