Difference between [square brackets] and *asterisk

后端 未结 5 2105
遇见更好的自我
遇见更好的自我 2020-11-27 04:03

If you write a C++ function like

void readEmStar( int *arrayOfInt )
{
}

vs a C++ function like:

void readEmSquare( int arrayOfInt[] )
{
}
         


        
5条回答
  •  无人及你
    2020-11-27 04:35

    C++ Standard 13.1.3

    — Parameter declarations that differ only in a pointer * versus an array [] are equivalent. That is, the array declaration is adjusted to become a pointer declaration (8.3.5). Only the second and subsequent array dimensions are significant in parameter types (8.3.4). [Example:

     int f(char*);
     int f(char[]);  // same as f(char*);
     int f(char[7]);  // same as f(char*);
     int f(char[9]);  // same as f(char*);
     int g(char(*)[10]);
     int g(char[5][10]);  // same as g(char(*)[10]);
     int g(char[7][10]);  // same as g(char(*)[10]);
     int g(char(*)[20]);  // different from g(char(*)[10]);
    

    —end example]

提交回复
热议问题