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 are the characteristics of Class Members in C++?

0 Answers  


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

0 Answers  


Explain what you mean by a pointer.

0 Answers   TCS,


Am pass the 10000 records to target in target I will take commit interval 15000 when I was stop the work flow what will happened

0 Answers  


What do you mean by late binding?

0 Answers  






what is upcasting in C++?

0 Answers  


How does a copy constructor differs from an overloaded assignment operator?

0 Answers  


pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count all the paper bills in the number being input.. example: enter a number: 3886 there is/are: 3 ->1000 1 ->500 3 ->100 1 ->50 1 ->20 1 ->10 1 ->5 1 ->1 example2: enter a number: 728 there is/are: 0 ->1000 1 ->500 2 ->100 0 ->50 1 ->20 0 ->10 1 ->5 3 ->1

4 Answers  


What is the need of a destructor?

0 Answers  


What is scope in c++ with example?

0 Answers  


Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?

0 Answers  


how to explain our contribution in the project?

0 Answers   Wipro, Yahoo,


Categories