Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. // Copy an array in C++ using pointers
  2.  
  3. #include<iostream.h>
  4. using namespace std;
  5.  
  6. void main()
  7. {
  8. char name[] = {'S','P','A','R','T','A','N'};
  9. char copy[7];
  10. char *p1, *p2;
  11. p1 = name;
  12. p2 = copy;
  13. while(*p1) *p2++ = *p1++;
  14. *p2 = 0;
  15. cout<<"Here is the original name array:n";
  16. p1 = name;
  17. cout<<name<<"n";
  18. while(*p1) cout<< *p1++ <<" ";
  19. cout<<endl;
  20. cout<<"Here is the copy:n";
  21. p1 = copy;
  22. while(*p1) cout<< *p1++ <<" ";
  23. cout<<endl;
  24. }
  25.  
  26. char name[] = {'S','P','A','R','T','A','N'};
  27.  
  28. char name[] = "SPARTAN";
  29.  
  30. char name[] = {'S','P','A','R','T','A','N',''};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement