二维指针 与 一维指针
来源:互联网 发布:爱淘宝1元口令 编辑:程序博客网 时间:2024/05/01 02:33
void fun(char *s){ s = (char *)malloc(100); cout << &(s) << endl; strcpy(s,"i love you"); cout << s << endl; }int main(){ char *str = new char[100]; strcpy(str,"you and me"); cout << &str << endl; fun(str); cout << &str << endl; cout << str << endl;;}
换成二维指针
void fun(char **s){ *s = (char *)malloc(100); cout << &(*s) << endl; strcpy(*s,"i love you"); cout << *s << endl; }int main(){ char *str = (char *)malloc(100); strcpy(str,"you and me"); cout << &str << endl; fun(&str); cout << &str << endl; cout << str << endl;}
结果成了
很明显str的内容变了,但是其指针位置还是没有改变,倒是fun中的s变了
- 二维指针 与 一维指针
- 指针与一维、二维数组
- [C语言]二维指针与一维指针
- 二维指针和一维指针
- 二维数组与一维数组指针变量的关系
- 一/二维数组与指向一/二维数组的指针
- 二维指针 与 指针数组
- 指针与二维指针、引用
- C语言指针与二维数组(二维数组与一维数组关系)
- 二维指针与二维数组
- 二维数组与二维指针
- 二维数组与二维指针
- 二维数组与指针
- 二维数组与指针
- 二维数组与指针
- 指针与二维数组
- 指针与二维数组
- 二维数组与指针
- 简单工厂模式和工厂方法模式及实例(总结)
- android Timer的用法实例
- vc6.0处理wps文字
- cocos2d-x与ISO内存管理
- android 使用jni
- 二维指针 与 一维指针
- VMware Server运行CentOS报Guest operating system 'centos' is not supported
- 正则表达式30分钟入门教程
- 第七周第三个任务 星号图
- java.lang.OutOfMemoryError: Java heap space 解决方法
- JNI java.lang.UnsatisfiedLinkError
- 七夕恋歌
- VB记录集参数
- PS修改图片上文字的几种方法 图+文