Examveda

Determine Output:
void main()
{
      char *p="hi friends", *p1;
      p1=p;
      while(*p!='\0') ++*p++;
      printf("%s", p1);
}

A. hi friends

B. ij!gsjfoet

C. hj grjeodt

D. None of These

Answer: Option B

Solution (By Examveda Team)

++*p++ will be parse in the given order :
1. *p that is value at the location currently pointed by p will be taken
2. ++*p the retrieved value will be incremented
3. when ; is encountered the location will be incremented that is p++ will be executed.


This Question Belongs to C Program >> C Miscellaneous

Join The Discussion

Comments (5)

  1. Yousef Walid
    Yousef Walid:
    9 months ago

    The question should be
    void main()
    {
    char p[]="hi friends", *p1;
    p1=p;
    while(*p1!='') ++*p1++;
    printf("%s",p);
    }
    for the answer to be correct

  2. WG KIM
    WG KIM:
    6 years ago

    The question should be modified as
    {
    char p[20] = "hi friends", * p1;
    p1 = p;
    while (*p1 != '') ++*p1++;
    printf("%sn", p);
    }

  3. Abdelbadie Belmouhcine
    Abdelbadie Belmouhcine:
    8 years ago

    Hello,
    This code must provide a runtime error because p is pointed to a literal string, which is unmodifiable.
    Thanks.

  4. Abhishek Singh
    Abhishek Singh:
    8 years ago

    Give full ans in brief !please.

  5. Gurpreet Gandhi
    Gurpreet Gandhi:
    8 years ago

    P1 pointer is not effected by the moment of p1(they are copy of the same string hi friends) hence the answer should be hi friends , isn't it ??

Related Questions on C Miscellaneous