Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copy an array in C++ using pointers
- #include<iostream.h>
- using namespace std;
- void main()
- {
- char name[] = {'S','P','A','R','T','A','N'};
- char copy[7];
- char *p1, *p2;
- p1 = name;
- p2 = copy;
- while(*p1) *p2++ = *p1++;
- *p2 = 0;
- cout<<"Here is the original name array:n";
- p1 = name;
- cout<<name<<"n";
- while(*p1) cout<< *p1++ <<" ";
- cout<<endl;
- cout<<"Here is the copy:n";
- p1 = copy;
- while(*p1) cout<< *p1++ <<" ";
- cout<<endl;
- }
- char name[] = {'S','P','A','R','T','A','N'};
- char name[] = "SPARTAN";
- char name[] = {'S','P','A','R','T','A','N','