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

How size of a class can be calulated?

2 Answers  


What is the most useful programming language?

0 Answers  


What are keywords in c++?

0 Answers  


Tell me difference between constant pointer and pointer to a constant.

0 Answers   Honeywell, Zomato,


What is abstraction in c++ with example?

0 Answers  


What is implicit conversion/coercion in c++?

1 Answers  


Explain polymorphism?

0 Answers  


a class that maintains a pointer to an object that is programatically accessible through the public interface is known as?

2 Answers   CTS,


What is c++ and its features?

0 Answers  


Explain the concept of inheritance in C++.

3 Answers  


What are the advantages of early binding?

0 Answers  


Comment on local and global scope of a variable.

0 Answers  


Categories