szxwpmj
szxwpmj

Reputation: 465

What's the differences between `int*[1]` and `int(*)[1]`?

using T1 = int*[1];
using T2 = int(*)[1];

T1 t1;
T2 t2;

t1[0] = 0;   // ok
t2[0] = 0;   // error : array type 'int [1]' is not assignable
t2    = t1;  // error : array type 'int [1]' is not assignable
t2    = &t1; // error : array type 'int [1]' is not assignable
t2    = 0;   // ok

Why is t2[0](/t1) not assignable?

What's the differences between int*[1] and int(*)[1]?

Update:

int n[1];
t2 = &n; // ok

Upvotes: 3

Views: 332

Answers (1)

llllllllll
llllllllll

Reputation: 16434

int*[1] is an array of length 1, whose element is int*.

int(*)[1] is a pointer, which points to array int[1]. Thus t2[0] is an array int[1], which is not assignable.

Upvotes: 2

Related Questions