#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定義引用,y是x的引用
int &y=x;
//打印x和y的值
cout<<x<<endl;
cout<<y<<endl;
//修改y的值
y = 6;
//再次打印x和y的值
cout<<x<<endl;
cout<<y<<endl;
return 0;
}
using namespace std;
int main(void)
{
int x = 3;
//定義引用,y是x的引用
int &y=x;
//打印x和y的值
cout<<x<<endl;
cout<<y<<endl;
//修改y的值
y = 6;
//再次打印x和y的值
cout<<x<<endl;
cout<<y<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
cout<<"看這個(gè),比聽(tīng)專(zhuān)業(yè)課的叫獸在講臺(tái)上空講效率高多了!"<<endl;
return 0;
}
using namespace std;
int main()
{
cout<<"看這個(gè),比聽(tīng)專(zhuān)業(yè)課的叫獸在講臺(tái)上空講效率高多了!"<<endl;
return 0;
}
2017-06-03
#include <string.h>
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請(qǐng)100個(gè)char類(lèi)型的內(nèi)存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內(nèi)存中
strcpy(str, "Hello imooc");
//打印字符串
cout<<str<<endl;
//釋放內(nèi)存
delete [] str;
str=NULL;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請(qǐng)100個(gè)char類(lèi)型的內(nèi)存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內(nèi)存中
strcpy(str, "Hello imooc");
//打印字符串
cout<<str<<endl;
//釋放內(nèi)存
delete [] str;
str=NULL;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
cout << 6 << endl;
cout<<8<<endl;
return 0;
}
這也可以通過(guò)..嘖嘖
using namespace std;
int main(void)
{
cout << 6 << endl;
cout<<8<<endl;
return 0;
}
這也可以通過(guò)..嘖嘖
很多人的迷惑
&的意思:
取地址符,這時(shí)候他用于數(shù)據(jù)的前面,比如int a=&b;
C++里還使用&作為引用符,如果你確認(rèn)程序是標(biāo)準(zhǔn)的C而非C++的話,那么可以排除是引用了。引用也用于數(shù)據(jù)前面,它只在定義和聲明時(shí)使用,如int &othername=name;
int &a=b; //定義時(shí)使用在等號(hào)左側(cè),是引用
int *a=&b; //在等號(hào)右側(cè),并單獨(dú)在數(shù)據(jù)之前,是取地址
int a=(&b) & 0xffff; //第一個(gè)&是用于取b的內(nèi)存中的地址,第二個(gè)&是按位與,即保留b地址值的低16位,高16位數(shù)值被清零(32位處理器下).
&的意思:
取地址符,這時(shí)候他用于數(shù)據(jù)的前面,比如int a=&b;
C++里還使用&作為引用符,如果你確認(rèn)程序是標(biāo)準(zhǔn)的C而非C++的話,那么可以排除是引用了。引用也用于數(shù)據(jù)前面,它只在定義和聲明時(shí)使用,如int &othername=name;
int &a=b; //定義時(shí)使用在等號(hào)左側(cè),是引用
int *a=&b; //在等號(hào)右側(cè),并單獨(dú)在數(shù)據(jù)之前,是取地址
int a=(&b) & 0xffff; //第一個(gè)&是用于取b的內(nèi)存中的地址,第二個(gè)&是按位與,即保留b地址值的低16位,高16位數(shù)值被清零(32位處理器下).
2017-05-16