Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

C%20%20%20Interview%20Questions%20and%20Answers

Question: Write a fucntion that will reverse a string.
Answer:
char *strrev(char *s)
{
int i = 0, len = strlen(s);
char *str;
if ((str = (char *)malloc(len+1)) == NULL)
/*cannot allocate memory */
err_num = 2;
return (str);
}
while(len)
str[i++]=s[?len];
str[i] = NULL;
return (str);
}
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook