Sample 4.20:ptrstr.cpp
2013-12-02 22:08
423 查看
#include<iostream> #include<cstring> int main() { using namespace std; char animal[20] = "bear"; const char * bird = "wren"; char * ps; cout << animal << " and "; cout << bird << "\n"; cout << "Enter a kind of animal: "; cin >> animal; ps = animal; cout << ps << "s!\n"; cout << "Before using strcpy(): \n"; cout << animal << " at " << (int *) animal << endl; cout << ps << " at " << (int *) ps << endl; ps = new char [strlen(animal) + 1]; strcpy(ps, animal); cout << "After using strcpy(): \n"; cout << animal << " at " << (int *) animal << endl; cout << ps << " at " << (int *)ps << endl; delete [] ps; return 0; }
相关文章推荐
- Sample 4.19:addpntrs.cpp
- Sample 4.18:arraynew.cpp
- Sample 4.17:use_new.cpp
- Sample 4.16:init_ptr.cpp
- Sample 4.15:pointer.cpp
- Sample 4.14:address.cpp
- Sample 4.13:arrstruct.cpp
- C语言动态存储分配
- Sample 4.12:assgn_st.cpp
- Sample 4.11:structur.cpp
- Sample 4.9:strtype3.cpp
- Sample 4.8:strtype2.cpp
- Sample 4.7:strtype1.cpp
- Sample 4.6:numstr.cpp
- Sample 4.5:instr3.cpp
- Sample 4.4:instr2.cpp
- Sample 4.3:instr1.cpp
- Sample 4.2:string.cpp
- Keil C51对C语言的关键词扩展之十七: sbit
- c++写的一个简单的管理系统