string palindrome logic in c with example:
What will be the output of below program? And how many times for loop will loop through?
char name = "skill";
int start = 0;
int end = strlen(name)-1;
int middle = (start+end)/2;
int rev = 0;
for(int i = start; i<=middle; i++, end--)
if(name[i] != name[end])
rev = 1;
success, for loop will loop for 5 times.
fail, for loop will loop for 1 time.
fail, for loop will loop for 5 times.
success, for loop will loop for 1 time.
fail, for loop will loop for 1 time. because 's' is the first character and 'l' is the last character. both are not batching, so it breaks for loop when ever there is no match, with out going for next iteration.
Back To Top