What does "*&" mean in C + + function parameters? ”

Source: Internet
Author: User

typedef struct BITNODE
{
char value;
Bitnode *lchild,*rchild;
}bitnode,*bitree;

void Creattree (bitnode* &root,char *pre,int l1,int r1,char *in,int l2,int R2);

/* What does *& stand for? Https://zhidao.baidu.com/question/2266744263935050308.html

This is the syntax for C + +,& The reference argument in the formal parameter,
Lnode * &LST; The Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and the & in &lst indicates the reference argument, which is an alias representing the argument.
Standard C does not support this notation.

Ask

& not address characters? What does the reference parameter mean?

Chase Answer

& in the variable definition area, indicating the reference, pay attention to its usage,
& in the variable operation area, which represents the fetch address character, such as:

int x=10, *p=&x; Here & function on X, is to take the address character
int &x; Reference is a new feature introduced by C + +, you do not want to learn C + +, the above code you do not understand. The & Here is quoted. In general, this form will appear in the formal parameter.

Lnode * &LST; The Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and the & in &lst indicates the reference argument, which is an alias representing the argument. Manipulating reference variables is equivalent to manipulating real parametric



*/

Binary tree using pre-order and middle order (source code):

    1. #include <iostream>
    2. #include <cstdio>
    3. #include <cstdlib>
    4. #include <cstring>
    5. using namespace std;;
    6. const int n=;
    7. typedef struct bitnode
    8. {
    9. char value;
    10. Bitnode *lchild,*rchild;
    11. }bitnode,*bitree;
    12. / * What does *& stand for?
    13. This is the syntax for C + +,& The reference argument in the formal parameter,
    14. Lnode * &LST; Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and that the & in &lst indicates the reference argument, which is an alias representing the argument.
    15. standard C does not support this notation.
    16. questioning
    17. & not address characters? What does the reference parameter mean?
    18. Chase Answer
    19. & in the variable definition area, indicating the reference, pay attention to its usage,
    20. & in the variable operation area, which represents the fetch address character, such as:
    21. int x=10, *p=&x;//here & function on X, is take address character
    22. int &x;//reference is a new feature introduced by C + +, you do not learn C + +, the above code you do not understand. The & Here is quoted. In general, this form will appear in the formal parameter.
    23. Lnode * &LST; Lnode * is a whole, indicating that the variable type is a Lnode class pointer, and that the & in &lst indicates the reference argument, which is an alias representing the argument. Manipulating reference variables is equivalent to manipulating real parametric
    24. */
    25. void creattree(bitnode* &root,char *pre,int L1,int R1,char *in,int L2, int R2)
    26. {
    27. if (L1<=R1&&L2<=R2)
    28. {
    29. int KEY=PRE[L1];
    30. int midindex=-1;
    31. For (int i=l2;i<=r2;i++)
    32. {
    33. if (in[i]==key)
    34. {
    35. Midindex=i;
    36. Break ;
    37. }
    38. }
    39. root= (Bitnode *)malloc (sizeof (Bitnode));
    40. root->value=key;
    41. root->lchild=NULL;
    42. root->rchild=NULL;
    43. int llen=midindex-l2;
    44. Creattree (Root->lchild, Pre, l1+1, L1+llen, in, L2, Midindex-1);
    45. Creattree (Root->rchild, Pre, l1+llen+1, R1, in, midindex+1, r2);
    46. }
    47. }
    48. void postordertraverse(bitnode *&root)
    49. {
    50. if (root->lchild)
    51. Postordertraverse (Root->lchild);
    52. if (root->rchild)
    53. Postordertraverse (Root->rchild);
    54. printf ("%c", Root->value);
    55. }
    56. int main()
    57. {
    58. Char pre[n],in[n];
    59. while (scanf ("%s", pre)!=eof)
    60. {
    61. scanf ("%s", in);
    62. int len1=strlen (pre);
    63. int len2=strlen (in);
    64. Bitnode *root=NULL;
    65. Creattree (Root,pre,0,len1-1,in,0,len2-1);
    66. Postordertraverse (root);
    67. printf ("\ n");
    68. }
    69. return 0;
    70. }

What does "*&" mean in C + + function parameters? ”

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.