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

when can we use copy constructor?

6 Answers   HP,


What is expression parser in c++

0 Answers   Mphasis,


What is function overloading in C++?

0 Answers  


Why we use #include iostream in c++?

0 Answers  


What will happen if when say delete this ?

7 Answers  






How many storage classes are available in C++?

1 Answers  


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

0 Answers  


Write about the members that a derived class can add?

0 Answers  


wrong statement about c++ a)code removably b)encapsulation of data and code c)program easy maintenance d)program runs faster

11 Answers  


What is a dll entry point?

0 Answers  


How the compilers arranges the various sections in the executable image?

1 Answers  


Write a program in C++ for Fibonacci series

0 Answers   Axtria, ITC Indian Tobacco Company,


Categories