dud3 dud3 - 11 months ago 74
C Question

Array of pointers evaluation

Can someone please tell me how would we evaluate the inner loop pointer:


How does it end up getting the second character from the argument?

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
while (--argc > 0 && (*++argv)[0] == '-') {

while ((c = *++argv[0])) {
switch (c) {

Answer Source

The array subscript operator has higher precedence than the prefix ++ and the dereference operator. The latter two operators have the same precedence and are evaluated from right to left. The expression in the second while loop is equivalent to:


The pointer to the string is obtained using the array subscript operator, then it is incremented by one using prefix increment, it now points to the second character, and then the character is obtained using the dereference operator.