What is the difference between typedef int array[3] and typedef int(array)[3]?
What is the difference between
typedef int array[3]
andtypedef int(array)[3]
?
They are the same.
Parentheses could be used when a pointer is being declared, with *
, and result in different types. In that case, parentheses could affect the precedence of []
or int
. However, this is not your case here.
If you run this code like this:
typedef int array[6];array arr={1,2,3,4,5,6};for(int i=0; i<6; i++) cout<<arr[i]<<" ";
And now you run this code like this:
typedef int (array)[6];array arr={1,2,3,4,5,6};for(int i=0; i<6; i++) cout<<arr[i]<<" ";
Both of those two types of code it generates the same output.This proves that both are same and the parentheses have no effect.