string - Can someone explain this C code? -
can explain reverse sentence code me? how first , second looping works? what's point of each of them?
main(){ char arr[255], *p; printf("enter string: "); gets(arr); for(p=arr; *p!='\0'; p++); for(p--; p>=arr; p--){ printf("%c",*p); } }
input:
i love
output:
uoy evol
the code printing in reverse input array.
for(p=arr; *p!='\0'; p++);
sets p
last (relevant) element of array (the null character)
for(p--; p>=arr; p--){ printf("%c",*p); }
starts last (none null) character , prints each 1 last first.
question you:
what happens if input array longet 255 chars? (answer below)
Comments
Post a Comment