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 constructor in C++?
What is the use of volatile keyword in c++? Give an example.
the first character in the variable name must be an a) special symbol b) number c) alphabet
write a C++ programming using for loop: * * * * * * * * * *
What is the extraction operator and what does it do?
Define pure virtual function?
Define pre-condition and post-condition to a member function in c++?
What is optimization in c++? when using volatile.optimization is not possible..what does this mean?
What are signs of manipulation?
What is c++ stringstream?
What do you mean by public protected and private in c++?
What is a container class? What are the types of container classes?