Write a function which takes a character array as input and
reverses it in place.
Answers were Sorted based on User's Feedback
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 |
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 |
What is the prototype of printf function?
What is c++ best used for?
We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?
Explain the difference between overloading and overriding?
How can we access protected and private members of a class?
If you had the following code: int x = 23; int *y; y = &x; The instruction y++; does what?
What is the difference in size of this two clasees? Class A { int a; char c; float f; } Class B { float f; char c; int a; }
Is c the same as c++?
Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.
what are the decision making statements in C++? Explain if statement with an example?
How would you represent an error detected during constructor of an object?
What is the full form of ios?