Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About the array subscripting operator

Quoting from the C11 standard :

Array subsripting (§ 6.5.2.1)

The definition of the subscript operator [] is that E1[E2] is identical to (*((E1)+(E2))).

I would like to know why are the brackets around E1 necessary (they were missing in the C89 standard), ie in which expression can (*(E1+(E2))) be different from (*((E1)+(E2))) ?

like image 856
md5 Avatar asked Aug 30 '12 16:08

md5


People also ask

What is Subscripting in C?

Array Subscript in C is an integer type constant or variable name whose value ranges from 0 to SIZE 1 where SIZE is the total number of elements in the array.

What is the use of subscript operator?

The Subscript or Array Index Operator is denoted by '[]'. This operator is generally used with arrays to retrieve and manipulate the array elements. This is a binary or n-ary operator and is represented in two parts: postfix/primary expression.

What is meant by array subscript?

Array Subscripts An array subscript allows Mathcad to display the value of a particular element in an array. It is used to refer to a single element in the array. The array subscript is created by using the [ key. This is referred to as the subscript operator.

What are the limitations of subscript operator in an array?

The above restrictions on the types of expressions required by the subscript operator, as well as the relationship between the subscript operator and pointer arithmetic, do not apply if you overload operator[] of a class. The first element of each array has the subscript 0 .


1 Answers

According to http://www.open-std.org/jtc1/sc22/wg14/www/docs/n841.htm, it is inserted just for clarity. The two expressions are the syntatically equivalent.

Public Comment Number PC-UK0103
Comment 1.
Category: Editorial change/non-normative contribution
Committee Draft subsection: 6.3.2.1
Title: Array subscripting example
Detailed description:

Paragraph 2 should replace "(*(E1+(E2)))" by "(*((E1)+(E2)))", to avoid confusion. Yes, I know that the syntactic chart makes it quite unambiguous, but the current wording in paragraph 2 is very confusing.

like image 164
kennytm Avatar answered Sep 30 '22 17:09

kennytm