Thread: Difference between "char* buf "and "char *buf"

  1. #1
    Registered User
    Join Date
    Dec 2003

    Difference between "char* buf "and "char *buf"

    Hi everyone,

    I am working with someone else's code that uses a struct defined as ...

    typedef struct RawFrame{
    unsigned char* buf;
    } RawFrame;
    If it were ...

    typedef struct RawFrame{
    unsigned char *buf;
    } RawFrame;
    then I would simply read this as a pointer called buf that points to char objects.

    How does the dereference (*) symbol being on the "char" instead of the pointer name (buf) change the meaning?

    Many thanks.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    It doesn't change it. It's a style preference.
    If you understand what you're doing, you're not learning anything.

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Something to keep in mind about one style vs. the other:

    char* x, y, z;
    Some people consider the above style to be a bad idea as it is tempting to read the declaration as three char pointers, when in fact there is one char pointer and two regular chars, like so:

    char *x, y, z;
    Of course if one was to declare three char pointers in the same line, it would look more like this:

    char *p, *q, *r;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  2. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  3. telnet
    By MrJake in forum C++ Programming
    Replies: 18
    Last Post: 11-13-2002, 06:21 PM
  4. Email attachment via smtp - how?!
    By lucky760 in forum C++ Programming
    Replies: 2
    Last Post: 07-04-2002, 07:59 PM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 06:55 AM