What is the difference between typedef int array[3] and typedef int(array)[3]? What is the difference between typedef int array[3] and typedef int(array)[3]? arrays arrays

What is the difference between typedef int array[3] and typedef int(array)[3]?


What is the difference between typedef int array[3] and typedef 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.


These are both equivalent. The parentheses do not alter the precedence of [] or int in this case.

The tool cdecl helps to confirm this:

  • int (a)[3] gives "declare a as array 3 of int"
  • int a[3] gives "declare a as array 3 of int"


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.