Skip to content

Instantly share code, notes, and snippets.

@johnhmj
Created June 2, 2011 13:51
Show Gist options
  • Select an option

  • Save johnhmj/1004464 to your computer and use it in GitHub Desktop.

Select an option

Save johnhmj/1004464 to your computer and use it in GitHub Desktop.
d062637776 (Sylar) [問題] c++雙重指標 Thu Jun 2 19:12:29 2011
// 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