0

Pointer

hello guys may i ask a question? so today we have a lab that ask a user to enter a word and then by using a pointer it reverse the input from the user, the name of that function file is void reverse (chars[])? sorry iam.new at this c++😁

3rd Nov 2016, 12:52 AM
Rhithym SF
Rhithym SF - avatar
3 Answers
0
#include <iostream> #include <cstring> using namespace std; void reverse(char a[]) { for(int i=0,j=strlen(a)-1;i<j;i++,j--) { int temp = a[i]; //swapping a[i] = a[j]; a[j] = temp; } for(int i=0;a[i]!='\0';i++) cout<<a[i]; } int main() { char a[10]; cin>>a; reverse(a); //function call return 0; } //Since it's a single word I have not considered spaces
3rd Nov 2016, 1:28 AM
kamal joshi
kamal joshi - avatar
0
if you can😀, can you explain how this is going to work?
3rd Nov 2016, 1:39 AM
Rhithym SF
Rhithym SF - avatar
0
ooo i got it now..thanks alot you my savior😂😂😂
3rd Nov 2016, 1:52 AM
Rhithym SF
Rhithym SF - avatar