C++基础 内置函数

内置函数

函数 方法 

函数在运行的时候 首先程序会走到Main函数 执行a函数  然后跳转到a函数体里 执行a函数体方法 返回到Main函数  这就会产生

很多的空间和时间  

内置函数就是虽然我也写函数 但是 实际运行代码都是在main里 

比方说 如果下面的代码


#include "stdafx.h"
#include <iostream>
#include "stdlib.h"
using namespace std;

inline void Mess(int &a, int &b,char &str);

int _tmain(int argc, _TCHAR* argv[])
{
	int a=10,b =10;
	char str ='U';
 
	Mess(a,b,str);
	cout<<a<<" "<< str <<" "<<b<<endl;
	system("pause");
	return 0;
}

inline void Mess(int &a, int &b,char &str)
{
	a=a+2;
	b=b-5;
	str='C';
}

实际执行是

int _tmain(int argc, _TCHAR* argv[])
{
	int a=10,b =10;
	char str ='U';
 
	//Mess(a,b,str);
	 a=a+2;
	b=b-5;
	str='C';
	cout<<a<<" "<< str <<" "<<b<<endl;
	system("pause");
	return 0;
}

就会快一些 当然 内置函数使用是有限制的

使用内置函数可以节省运行时间 但是却增加了程序的长度

一般只将规模很小(一般为5个语句以下)而使用频繁的函数  声明为内置函数

内置函数中不能包括复杂的控制语句 比如 循环 switch语句

声明Inline 只是程序设计者对编译系统提出一个建议 而不是指令 

发布了279 篇原创文章 · 获赞 43 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/q465162770/article/details/103456185