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

Explain the static member function.

0 Answers  


When should we use multiple inheritance?

0 Answers  


Can we make copy constructor private in c++?

0 Answers  


1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main() { int v=10; afunction(&v); cout<<v; } a) Outputs 12 b) Outputs 10 c) Outputs the address of v

5 Answers   Quark,


What is a singleton class c++?

0 Answers  






Can a constructor throw a exception? How to handle the error when the constructor fails?

1 Answers  


What is Pure Virtual Function? Why and when it is used ?

10 Answers   Lucent, Sona,


What does override mean in c++?

0 Answers  


what is oops and list its features in c++?

0 Answers  


What is a rooted hierarchy?

0 Answers  


Can non-public members of another instance of the class be retrieved by the method of the same class?

0 Answers  


What is a c++ vector?

0 Answers  


Categories