1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Consideration on pointer declarations

Discussion in 'C' started by Alex, Apr 12, 2009.

  1. Alex

    Alex New Member

    Joined:
    Oct 1, 2006
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    In all the code I've seen as of today, the * has always been
    associated to the variable instead of the type:
    char *pc;
    I would have expected (and I tend to write):
    char* pc;
    I know the first syntax is correct because
    char *pc1, *pc2; //works
    char* pc1, pc2; //does not work
    It may seem futile
     
  2. johny_1015_1981

    johny_1015_1981 New Member

    Joined:
    Oct 5, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    That is a common mistake made by lots of people I knew

    When a user declare somthing like
    char* pc1,pc2;
    It does not mean that both pc1 and p2 are declared as pointer.
    Only pc1 is declared as pointer but not pc2. pc2 is just a char type variable.

    char* pc1, pc2;
    char *pc1, pc2; both are same.
     

Share This Page