mkagenius's blog

By mkagenius, 9 years ago, In English

Code:

#include
int main()
{
    char *s[]={"codeforces","russia","contest"};
    char **p;
    p = s;
    printf("%s ",++*p);
    printf("%s ",*p++);
    printf("%s ",++*p);
    scanf("%*d");
    return 0;
}
Output: odeforces odeforces ussia

Please someone explain the output( 2nd and 3rd string).
 
 
 
 
  • Vote: I like it
  • +9
  • Vote: I do not like it

9 years ago, # |
  Vote: I like it 0 Vote: I do not like it
p={"odeforces","russia","contest"}
2: *(p++)
p={"russia","contest"}
3: ++(*p)
p={"ussia","contest"
  • 9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    2nd output still not clear, *(p++) , p gets incremented first ,
    so, p =  { "russia", "contest"}
    now how using * will print "odeforces" ;
    • 9 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it
      This is postincrement operator. It returns p and then increments it. It return {"odeforces","russia","contest"} and then transform into {"russia", "contest"}.