936 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

1.5k
views
1 answers
3 votes
KISHALAY DAS asked Nov 15, 2016
1,482 views
245
views
1 answers
0 votes
Debargha Mitra Roy asked Apr 16
245 views
#include <stdio.h> int main() { int a[3][2] = {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.)The output is __________.
856
views
1 answers
0 votes
Mrityudoot asked Apr 24, 2023
856 views
For arrays with more given elements than its size, why does doing a[i] print garbage value but *a+i brings the correct value, despite them being the same thing (a[i] = *a+i)int a[ ... , Garbage printf( %d , *a+i; // gives 1, 2, 3, 4}
387
views
1 answers
0 votes
jaikant asked Apr 14, 2023
387 views
I have confusion regarding pointers, why 1D array and 2D array works differently. For e.g. I have written a code#include <stdio.h>int main(){ int arr[6 ... isn't *marr suppose to print 11' in place of some longed signed value.