Some knowledge points about array names and pointers

1. The name of the array can be regarded as a pointer to the first element of the array.

#define debug qDebug()<<
int main(int argc, char *argv[])
{
    char v[] = "this is a string";
    char * p2 = v;
    debug strlen(p2);
    debug strlen(v);
}

 

An implicit conversion is done here:

    char * p2 = "this is a string";

This is a string of c language style.

2. There is no conversion from pointer to array.

3. Array can use range for loop:

    char v[] = "this is a string";
    for(auto & c:v)
    {
        debug c;
    }

4. You cannot pass the array to the function by value. Usually the pointer to the first element of the array (array name) is passed, but in this way, the number of elements in the array may cause the array to go out of bounds, so the usual way is Store the contents of the array in the container and pass the container to the function.

Guess you like

Origin blog.csdn.net/kenfan1647/article/details/113809869