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 |
Why is c++ is better than c?
What is std namespace in c++?
What is an Iterator class?
Why do we use constructor?
What are different types of typecasting supported by C++
Which is not a valid keyword a) public b) protected c) guarded
What is helper in c++?
What kind of problems can be solved by a namespace?
C++ program output? Explain output of this program. #include <iostream> using std::cout; using std::cin; int main() { cout<<cout<<' '; cout<<cin; return 0; } It prints some address in hexadecimal. what is it?
Is it possible for a member function to delete the pointer, named this?
what is data abstraction in C++?
List the features of oops in c++?