设为首页 加入收藏

TOP

vector作为参数的三种传参方式(二)
2017-10-12 17:59:00 】 浏览:8917
Tags:vector 作为 参数 方式
unction3.vec[i][j]:
"<<endl; 81 for(int i=0;i<2;i++) 82 { 83 for(int j=0;j<3;j++) 84 cout<<(*vec)[i][j]<<" "; 85 cout<<endl; 86 } 87 } 88 89 int main() 90 { 91 //创建2*3的vector容器v,初始值均初始化为0 1 2 1 2 3 92 std::vector<std::vector<int> > v(2,std::vector<int>(3,0)); 93 for(int i=0;i<2;i++) 94 { 95 for(int j=0;j<3;j++) 96 v[i][j]=i+j; 97 } 98 99 //打印v的地址 100 cout<<"&v:"<<&v<<endl; 101 //打印v[i]的地址(即第一层vector的地址) 102 cout<<"&v[i]:"<<endl; 103 for(int i=0;i<2;i++) 104 cout<<&v[i]<<endl; 105 //打印v的各元素地址 106 cout<<"&v[i][j]:"<<endl; 107 for(int i=0;i<2;i++) 108 { 109 for(int j=0;j<3;j++) 110 cout<<&v[i][j]<<" "; 111 cout<<endl; 112 } 113 114 cout<<"---------------------------"<<endl; 115 //打印v的各元素值 116 cout<<"v[i][j]:"<<endl; 117 for(int i=0;i<2;i++) 118 { 119 for(int j=0;j<3;j++) 120 cout<<v[i][j]<<" "; 121 cout<<endl; 122 } 123 124 function1(v); 125 function2(v); 126 function3(&v); 127 128 return 0; 129 }

 

输出(为便于观察,简单处理了一下效果):

 

简而言之,vector的内部存储模型是这个样子(以main()函数中的v为例):

 关于12个字节的问题,请参考博客http://blog.csdn.net/kangroger/article/details/38386099

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇进程查杀 下一篇Leetcode:42. Trapping Rain Water

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目