in c, when allocating a new dynamic memory with malloc:
int* x = (int*)malloc(sizeof(x));
int y = 10;
is this line:
*x = y;
equal to this line:
x[0] = y;
The definition of the []
operator is: given ex1[ex2]
, it is guaranteed to be equivalent to
*((ex1) + (ex2))
Where ex1
and ex2
are expressions.
In your case x[0]
== *(x + 0)
== *(x)
== *x
.
See Do pointers support "array style indexing"? for details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.