Thursday 14 March 2013

printf("\n%c%c%c%c",c[ i ],*(c+i),*(i+c),i[c]);


main()
{
    char c[ ]="man";
    int i;
    for(i=0;c[ i ];i++)
    printf("\n%c%c%c%c",c[ i ],*(c+i),*(i+c),i[c]);
}
Answer:
            mmmm
             aaaa
            nnnn

Explanation:
c[i], *(i+c), *(c+i), i[c] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here c is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of  C  it is same as s[i].


Blog Author: Vijay Kumar

Go to: Java Aptitude

No comments:

Post a Comment