Question : What will be the Output of the Program.
#include<stdio.h> void main() { char s[ ]="cat"; int i; for(i=0;s[ i ];i++) printf("\n%c %c %c %c",s[ i ],*(s+i),*(i+s),i[s]); }
Answer -
c c c c a a a a t t t t
Explanation :
- Array name is the base address of the array.
- Here ‘s’ is the base address.
- ‘i’ is the index number/displacement from the base address.
- Array A[i] can be Represented as -
*(Array name + Displacement) = *(A + i) = Value at (Array name + Displacement) = Value at (Base Address + Displacement)
So
s[i] = *(s + i) i[s] = *(i + s)