Wednesday, February 16, 2011

Find Output .


#include<stdio.h>
int main()
{
  char *s[] = { "knowledge","is","power"};
  char **p;
  p = s;
  printf("%s ", ++*p);
  printf("%s ", *p++);
  printf("%s ", ++*p);

  getchar();
  return 0;
}

4 comments:

  1. Here as p = s.
    p is pointing to knowledge.
    and when we do ++*p then p would point to
    " nowledge ".
    so and then when we do *p++ then here the whole pointer p would move to second element of s i.e. "is".
    but as it is post increment the ans remains same
    " knowledge"
    then when we do ++*p so it moves to ' s ' of is.
    so final output would be
    nowledge, nowledge and s.

    ReplyDelete
  2. will you please explain how ++*p points to "nowledge"?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete