What do parentheses in a C variable declaration mean?

前端 未结 5 1068
忘了有多久
忘了有多久 2020-12-04 19:23

Can someone explain what this means?

int (*data[2])[2];
5条回答
  •  没有蜡笔的小新
    2020-12-04 20:06

    If you have an array:

    int myArray[5];
    int * myArrayPtr = myArray;
    

    Would be perfectly reasonable. myArray without the brackets is a pointer to an int. When you add the brackets its like you deference the pointer myArray. You could write...

    myArrayPtr[1] = 3;
    

    Which is perfectly reasonable. Using parenthesis just makes things harder to read and understand IMO. And they show that people don't understand pointers, arrays, and pointer arithmetic, which is how the compiler or linker goes from one to the other. It seems with parenthesis you do get bounds checking though.

提交回复
热议问题