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 searching? Explain linear and binary search.
Write a program to find the Factorial of a number
How delete [] is different from delete?
Is empty stack c++?
What are the defining traits of an object-oriented language?
why and when we can declar member fuction as a private in the class?
What do you mean by inheritance in c++? Explain its types.
Is there any difference between dlearations int* x and int *x? If so tell me the difference?
What are separators in c++?
Is vector a class in c++?
write a porgram in c++ that reads an integer and print the biggest digit in the number
What is a class template in c++?