Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly use array subscripting notation?

Tags:

arrays

c

pointers

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?

like image 617
Mr'Black Avatar asked May 11 '26 07:05

Mr'Black


1 Answers

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.

like image 170
Sourav Ghosh Avatar answered May 13 '26 01:05

Sourav Ghosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!