CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2012
    Location
    INDIA
    Posts
    25

    Unhappy Reference to a pointer

    I am unable to get "reference to a pointer".
    Here:

    char*p = "hello";
    char*&k = p;


    while creating reference to a pointer why we have to write *&k , why not &*k?
    TANUSHREE-AGRAWAL...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Reference to a pointer

    Quote Originally Posted by Tanushreeagr View Post
    I am unable to get "reference to a pointer".
    Here:
    Code:
    char*p  =  "hello";
    char*&k  =  p;
    while creating reference to a pointer why we have to write *&k , why not &*k?
    I recommend you:
    1. Change your code writing style to use spaces like
      Code:
      char* p  =  "hello";
      char*& k  =  p;
    2. Use Code tags while posting code snippets.

    Now about your question:
    Code:
    char a;	// character a
    char* p;	// p is a pointer to a character
    char& r;	// r is a reference to a character
    char*& rp;	// r is a reference to a pointer to a character
    char&* pr;	// r would be a pointer to a reference to a character
    Victor Nijegorodov

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

    Re: Reference to a pointer

    Quote Originally Posted by Tanushreeagr View Post
    I am unable to get "reference to a pointer".
    Here:

    char*p = "hello";
    char*&k = p;


    while creating reference to a pointer why we have to write *&k , why not &*k?
    That's the syntax for a reference.

    An int reference would be
    int&, so a char* reference is char*&.

  4. #4
    Join Date
    Feb 2012
    Location
    INDIA
    Posts
    25

    Re: Reference to a pointer

    ok Thanks...
    TANUSHREE-AGRAWAL...

  5. #5
    Join Date
    Feb 2012
    Location
    INDIA
    Posts
    25

    Re: Reference to a pointer

    How to create a new thread , PLEASE HELP ME!!!
    TANUSHREE-AGRAWAL...

  6. #6
    Join Date
    Feb 2012
    Location
    INDIA
    Posts
    25

    Re: Reference to a pointer

    #include <stdio.h>

    void main()
    {
    int x = 10 ;

    3 = x;

    }

    When we run the above program compiler error :"left operand must be l-value" occur , why it's telling about left operand while in the
    program 3 is on RHS... ????
    TANUSHREE-AGRAWAL...

  7. #7
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Reference to a pointer

    Quote Originally Posted by Tanushreeagr
    How to create a new thread , PLEASE HELP ME!!!
    1. Return to the list of threads in C++ (Non Visual C++ Issues) forum.
    2. Access the Post New Thread page through the button-like link.

    Quote Originally Posted by Tanushreeagr
    When we run the above program compiler error :"left operand must be l-value" occur , why it's telling about left operand while in the
    program 3 is on RHS... ????
    You are mistaken: 3 is on the left hand side.
    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

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured