3

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?

4
  • 2
    Why did you change +j to ++j? Commented Sep 14, 2016 at 21:07
  • ++j and +j have nothing to do with each other. ++j CHANGES j itself while +j simply adds j's value to whatever comes before in the code. Commented Sep 14, 2016 at 21:07
  • 1
    What is the type of strarray? Is it char**? Commented Sep 14, 2016 at 21:09
  • yes, Nikita, it is char**. The answer posted below solved my confusion. Commented Sep 14, 2016 at 21:13

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Sourav, it works, that little + was disturbing. i will check more about Array subscripting.
Nice reference to C11.
Nice. And the general rule here is: when we say a[i] we always mean *(a + i).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.