using namespace std;
void print(char **str){
++str;
cout<<*str<<endl;
}
int main() {
static char *arr[]={"hello", "world", "c++"};
char **ptr;
ptr=arr;
print(ptr);
return 0;
}
const char *a[]={ "fortran", " basic", "pascal", "java", "c++" };
cout << a[3] << endl; //打印 java
cout << *a[3] << endl; //打印 j int val = 1234; int* temp = &val; cout << temp << endl; //打印val的地址 cout << *temp << endl; //打印1234
总结:
1.cout一个char型指针会打印其中内容,而cout一个int型指针会打印其地址
2.cout一个char型指针的解引用会打印这个指针指向的内容即上述的'j',cout一个int型指针的解引用也会打印这个指针指向的内容即上述的1234
3.char *ptr = "java";指针形式存储的字符串是字符常量,最好加上const,数组a也最好加上