⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arguments.cpp

📁 C++中变量的例子,对于C++的初学者有一些帮助,可以更了解C
💻 CPP
字号:
// arguments.cpp : Defines the entry point for the console application.
//

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

string f1(string a)
{
	a+=" C++ in f1";
	return a;
}
string f2(string& a)
{
	a+=" C++ in f2" ;
	return a ;
}

string f3(const string& a)
{
	return a+" C++ in f3";
}
string f4(const string a)
{
	return a+" C++ in f4";
}

string& f5(string& a)
{
	return a;
}
const string& f6(string&a)
{
	return a;
}

const string f7(string a)
{
	return a;
}

int main(int argc, char* argv[])
{
	string s("Test");

#if 1	
	string& s1=f1(s);
	cout<<s1<<"\t"<<&s1<<endl;
	// s1=s    ;        //考虑一下这个时候s1的地址等不等于s呢
	cout<<s<<"\t"<<&s<<endl;

	s="Test";
	string& s2=f2(s);
	cout<<s2<<"\t"<<&s2<<endl;
	cout<<s<<"\t"<<&s<<endl;

	cout<<f1("Test")<<endl;
	//cout<<f2(" string")<<endl;
	cout<<f3("Test")<<endl;
	cout<<f4("Test")<<endl;

	string& s5=f5(s);
	cout<<s5<<"\t"<<&s5<<endl;
	cout<<s<<"\t"<<&s<<endl;
#endif

#if 0
	const string& s7=f7(s);

	cout<<s7<<"\t"<<&s7<<endl;
	cout<<s<<"\t"<<&s<<endl;
#endif
	

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -