Write a function which takes a character array as input and
reverses it in place.

Answers were Sorted based on User's Feedback



Write a function which takes a character array as input and reverses it in place...

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

Write a function which takes a character array as input and reverses it in place...

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

Post New Answer

More C++ General Interview Questions

Why is c++ is better than c?

0 Answers  


What is std namespace in c++?

0 Answers  


What is an Iterator class?

1 Answers  


Why do we use constructor?

0 Answers  


What are different types of typecasting supported by C++

1 Answers   CA,






Which is not a valid keyword a) public b) protected c) guarded

0 Answers  


What is helper in c++?

0 Answers  


What kind of problems can be solved by a namespace?

0 Answers  


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?

1 Answers  


Is it possible for a member function to delete the pointer, named this?

0 Answers  


what is data abstraction in C++?

0 Answers  


List the features of oops in c++?

0 Answers  


Categories