914 views
0 votes
0 votes
#include <stdio.h>

int main(void) {
    
static    char s[25]="TheCocaine Man";
    int i=0;
    char ch;
    ch=s[++i];
    
    printf("%c",ch);
    ch=s[i++];
    printf("%c \n",ch);
   ch=i++[s];
   printf("%c\n",ch);
   ch=++i[s];
   
   printf("%c ",ch);
    return 0;

}

how last ch print D?is  ++i[s] incremet index or value?

1 Answer

1 votes
1 votes
1) S[i] = *(S+i) = *(i+S) =i[S]

2) ++S[i] = ++*(S+i) = ++*(i+S) = ++i[S]

In second case --> ++i[S] is expanded to ++*(i+S) by the preprocessor. * and ++ both are unary operators and priority are same for both. So they will go for Right to Left associativity. So first *(i+S) will be computed which equals "C" and then is incremented to D

Related questions

3 votes
3 votes
1 answer
1
KISHALAY DAS asked Nov 15, 2016
1,464 views
0 votes
0 votes
1 answer
2
Debargha Mitra Roy asked Apr 16
188 views
#include <stdio.h int main() { int a[3] = {1, 3, 5, 7, 9, 11}; int *ptr = a[0]; ptr += sizeof(int); printf("%d", *ptr); return 0; }(Assume size of int to be $2$ bytes.)T...