zoukankan      html  css  js  c++  java
  • C++ 函数传参

    C++和C语言一样,也将数组视为指针。

    // ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
    //
    
    #include"stdafx.h"
    #include<iostream>
    #include<vector>
    
    
    
    void count(int a[10]){
    	for (int i = 0; i < 10; i++){
    		a[i] = i;
    	}
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	using namespace std;
    	int a[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
    
    	count(a);
    
    	cout << sizeof(a) << endl;
    
    	for (int i = 0; i < sizeof(a)/sizeof(int); i++){
    		cout << a[i] << endl;
    	}
    	
    
    	//program ending;
    	cin.get();
    	return 0;
    }
    
    
    
    

    注意:
    数组已初始化的情况下,后面代表的是下标,如a[10]是指a的第10个元素
    传递数组时,函数使用该变量的拷贝,但是使用数组时,函数将使用原来的数组。
    一般不许修改记得加 const常量修饰。

  • 相关阅读:
    STL——pair
    STL——stack
    Python学习之编程基础
    开学第一课,课课有总结
    DNS域名解析
    FTP文件传输服务
    DHCP原理及配置
    Linux中配置网卡
    indoe与block解析
    Linux系统安全管理
  • 原文地址:https://www.cnblogs.com/canbefree/p/5207092.html
Copyright © 2011-2022 走看看