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 searching? Explain linear and binary search.

0 Answers  


Write a program to find the Factorial of a number

0 Answers  


How delete [] is different from delete?

0 Answers  


Is empty stack c++?

0 Answers  


What are the defining traits of an object-oriented language?

0 Answers  






why and when we can declar member fuction as a private in the class?

0 Answers  


What do you mean by inheritance in c++? Explain its types.

0 Answers  


Is there any difference between dlearations int* x and int *x? If so tell me the difference?

16 Answers   Lason,


What are separators in c++?

0 Answers  


Is vector a class in c++?

0 Answers  


write a porgram in c++ that reads an integer and print the biggest digit in the number

0 Answers  


What is a class template in c++?

0 Answers  


Categories