Write a function which takes a character array as input and
reverses it in place.
Answers were Sorted based on User's Feedback
Answer / gumnam
void reverse(char *a)
{
char tmp;
int len = strlen(a) - 1;
for (int i = 0; i < len/2; i++)
{
tmp = a[i];
a[i] = a[len - i];
a[len - i] = tmp;
}
}
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / arun
#include<iostream>
using namespace std;
void reverse(char *a)
{
char *tmp = new char[strlen(a)];
memset(tmp,0,strlen(tmp));
int a1 = strlen(a);
a1 =a1-1;
for (int i = a1;i>=0; i--)
{
tmp[a1-i] = a[i];
}
cout<<tmp<<" "<<strlen(tmp)<<endl;
}
void main()
{
char *name = "Xerox";
reverse(name);
}
| Is This Answer Correct ? | 2 Yes | 2 No |
What is the difference between "overloading" and "overridding"?
How can you quickly find the number of elements stored in a a) static array b) dynamic array ?
What is heap sort in c++?
Why is main function important?
Is there any problem with the following: char *a=NULL; char& p = *a;?
What are default parameters? How are they evaluated in c++ function?
Define pure virtual function?
What will i and j equal after the code below is executed? Explain your answer.
How to defines the function in c++?
How is objective c different from c++?
How do you clear a buffer in c++?
What is a local variable?