一些C++知識

來源:互聯網
上載者:User

標籤:日常

1.內建函數:在編譯時間將所調用函數的代碼嵌入到主函數中。
例:#include < iostream >
using namespace std;
inline int max (int a,int b,int C)
{if(b>a) a=b;
if(c>a) a=c;
return a;
int main ()
{inti=7,j=10,k=25,m;
m=max(i,j,k);
cout << "max = " << m << endl ;
return 0;
結果:max=25

2.範圍運算子“::”:能指定所需要的範圍。
例:int main ()
{int a=5;//輸出局部變數a 的值
cout << a << endl ;//輸出全域變數a 的值
cout <<::a <<endl;
結果:
5(局部變數a 的值)
13.5(全域變數a 的值)
不能用“::”訪問函數中的局部變數。

3.動態分配/撤銷記憶體的運算子new和delete
例:
new int ;//開闢一個存放整數的空間,返回一個指向整型資料的指標
new int (100) ;//開闢一個存放整數的空間,並指定該整數的初值為100
new char [10 ];//開闢一個存放字元數組的空間,該數組有10 個元素
//返回一個指向字元資料的指標
new int[5] [4];//開闢一個存放二維整型數組的空間,該數組大小為5 4
float
p=new float (3.14159)//開闢一個存放實數的空間,並指定該實數的初值為3.1415
//將返回的指向實型資料的指標賦給指標變數p

一些C++知識

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.