Created
June 2, 2011 13:51
-
-
Save johnhmj/1004464 to your computer and use it in GitHub Desktop.
d062637776 (Sylar) [問題] c++雙重指標 Thu Jun 2 19:12:29 2011
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Integrated Development Environment | |
| // Visual C++ | |
| #include <iostream> | |
| #include <cstdlib> | |
| // | |
| // 主函式 | |
| int main(int argc, char** argv) | |
| { | |
| char str_array[7][5] = {"Mon", "Tue", "Web", "Thu", "Fri", "Sat", "Sun"}; | |
| char* str_ptr_array[7] = {static_cast<char*>(NULL)}; | |
| char** ptr = static_cast<char**>(NULL); | |
| // 雙重指標要有空間,字串指標陣列供指標使用 | |
| ptr = str_ptr_array; | |
| for (unsigned int i = 0; i < 7; i ++) | |
| { | |
| // 逐一複製每個字串的位址 | |
| str_ptr_array[i] = str_array[i]; | |
| } | |
| // 用雙重指標顯示 | |
| for (unsigned int i = 0; i < 7; i ++) | |
| { | |
| std::cout << ptr[i] << std::endl; | |
| } | |
| system("PAUSE"); | |
| return (0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment