Ok, I was assigned to do certain exercises out of my programming book for my class, I am having a bit of trouble and would appreciate some help. Here's the question:
"Let f be the following function:
(a) What is the value of f ( "abcd" , "babc") ?Code:int f(char *s, char *t) { char *p1, *p2; for (p1 = s; *p1; p1++) { for (p2 = t; *p2; p2++) if (*p1 == *p2) break; if (*p2 == '\0') break; } return p1-s; }
(b) What is the value of f ( "abcd" , "bcd") ?
(c) In general, what values does f return when passed two strings s and t?"
I put this code in a program and ran it myself. I may have did it wrong but for (a) I got 3 and for (b) I got 0. I don't really understand what is going on here and I would appreciate if someone could explain (c) to me.