dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: pointer declaration ambiguity

  1. #1
    Join Date
    Jun 2006
    Posts
    9

    pointer declaration ambiguity

    Hi

    If I have a declaration of the kind:

    int* a, *b;

    then would this make b a pointer to a pointer(**b) ?

    thanks in advance

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,554

    Re: pointer declaration ambiguity

    No. a and b are both int pointers.

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: pointer declaration ambiguity

    Which is why I always put the * next to the variable name when declaring more than one pointer on a line.

  4. #4
    Join Date
    May 2008
    Location
    *****, Nigeria
    Posts
    40

    Re: pointer declaration ambiguity

    Just been curious...those this

    Code:
    int* a, b;
    means d same thing with that above ?? cuz u can just declare

    Code:
    int a, b;
    on the same line.. those it work with pointers also ?? or its different..

    Regards,
    Richard Aberefa.

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,762

    Re: pointer declaration ambiguity

    No,
    Code:
    int* a, b;
    is equivalent to:
    Code:
    int* a;
    int b;
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: pointer declaration ambiguity

    Code:
    int *a, b;
    The above declares 'a' to be a pointer to an integer, and declares 'b' as an integer and is equivalent to:
    Code:
    int *a;
    int b;
    and aside from initialisation ordering it is the same as writing:
    Code:
    int b, *a;
    In order to declare both 'a' and 'b' as pointers to integers you would need to write.
    Code:
    int *a, *b;

  7. #7
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: pointer declaration ambiguity

    Quote Originally Posted by Lindley
    Which is why I always put the * next to the variable name when declaring more than one pointer on a line.
    Or even better, have one variable per row.
    Har Har

  8. #8
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: pointer declaration ambiguity

    Quote Originally Posted by PadexArt
    Or even better, have one variable per row.
    That is a far better practice.

  9. #9
    Join Date
    May 2008
    Location
    *****, Nigeria
    Posts
    40

    Re: pointer declaration ambiguity

    Thnx Amigo's; your making me enjoy my time studying C++; hope i dont reach a no go point where i'd get all confused an hooked up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)