Mr'Black
Mr'Black

Reputation: 284

How to properly use array subscripting notation?

I am trying to read correctly this :

*(strarray[i]+j)=0;

I was understanding something like :

strarray[i][++j] = 0;

or

strarray[i][++j] = '\0';

but is not exactly the same. How could it be written correctly as an array subscripting notation?

Upvotes: 3

Views: 152

Answers (1)

Sourav Ghosh
Sourav Ghosh

Reputation: 134366

Using the postfix array subscripting notation,

*(strarray[i]+j)=0;

will be

 strarray[i][j]=0;

Quoting the C11 standard, chapter §6.5.2.1, Array subscripting

A postfix expression followed by an expression in square brackets [] is a subscripted designation of an element of an array object. The definition of the subscript operator [] is that E1[E2] is identical to (*((E1)+(E2))). [...]

In your case, you can consider E1 as strarray[i] and E2 as j.

Upvotes: 5

Related Questions