string example in c:
What will be the below program output, and how many times for loop will loop through?
char name = "skills";
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 2 times.
fail, for loop will loop for 5 times.
fail, for loop will loop for 2 times. in first loop first char is 's' and last char is 's', so it proceeds to next loop. but in the next loop 'k' is not matching with 'l' , so it breaks loop. so total for loop will loop for 2 times.
Back To Top