본문 바로가기
C++

point to string

by SpeeDr00t 2016. 7. 29.
반응형

point to string

1.소스

#include <iostream> #include <cstring> using namespace std; int main( int argc , char ** argv ) { char cname[20] = "black falcon"; char * ps; ps = cname; cout << " before using strcpy " << endl; cout << " cname at = " << (int *)cname << endl; cout << " ps at = " << (int *)ps << "\n\n" << endl; ps = new char[strlen(cname) + 1 ]; strcpy( ps, cname ); cout << " after using strcpy " << endl; cout << " cname at = " << (int *)cname << endl; cout << " ps at = " << (int *)ps << endl; delete [] ps; return 0; }

결과

g++ -o ptrstr ptrstr.cpp hacker@ubuntu:~/cpp$ ./ptrstr before using strcpy cname at = 0x7ffc3ce82440 ps at = 0x7ffc3ce82440 after using strcpy cname at = 0x7ffc3ce82440 ps at = 0x10e3030 hacker@ubuntu:~/cpp$


반응형

'C++' 카테고리의 다른 글

Count Derangements  (0) 2016.08.03
using for with a string  (0) 2016.07.29
pointer  (0) 2016.07.28
hash string  (0) 2016.07.12
데이터 비교해서 sink 맞추기  (0) 2016.07.12