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

What is constructor in C++?

0 Answers  


What is the use of volatile keyword in c++? Give an example.

1 Answers  


the first character in the variable name must be an a) special symbol b) number c) alphabet

0 Answers  


write a C++ programming using for loop: * * * * * * * * * *

4 Answers   TCS,


What is the extraction operator and what does it do?

0 Answers  


Define pure virtual function?

0 Answers  


Define pre-condition and post-condition to a member function in c++?

0 Answers  


What is optimization in c++? when using volatile.optimization is not possible..what does this mean?

1 Answers  


What are signs of manipulation?

0 Answers  


What is c++ stringstream?

0 Answers  


What do you mean by public protected and private in c++?

0 Answers  


What is a container class? What are the types of container classes?

1 Answers  


Categories