02 C 基礎 引用( )

2021-08-17 11:21:48 字數 969 閱讀 1560

引用並非物件,相反的,它只是為了乙個已經存在的物件所起的另乙個名字

#include using namespace std;

/** * 左值引用

*/int main()

執行結果

val = 1024, &val = 0x28ff44, &refval = 0x28ff44, refval = 1024
1.1 引用報錯-初始值要滿足為物件

int &errorval = 10;如下報錯

..\src\helloword.cpp: in

function `int

main

()':

..\src\helloword.cpp:20: error: invalid initialization of non-const

reference

oftype

'int&'

from a temporary of

type

'int'

..\src\helloword.cpp:20: warning: unused variable 'errorval'

1.2 引用要與父物件型別保持一致
..\src\helloword.cpp: in

function `int

main

()':

..\src\helloword.cpp:21: error: invalid initialization of

reference

oftype

'int&'

from expression of

type

'double'

..\src\helloword.cpp:21: warning: unused variable 'errorval'

02C 垃圾炸彈

總時間限制 1000ms 記憶體限制 65536kb 描述2018年俄羅斯世界盃 2018 fifa world cup 開踢啦!為了方便球迷 比賽,莫斯科街道上很多路口都放置了的直播大螢幕,但是人群散去後總會在這些路口留下一堆垃圾。為此俄羅斯 決定動用一種最新發明 垃圾炸彈 這種 炸彈 利用最先進...

從頭開始 02 C語言基礎

include int main 總結 1.記憶體定址由大到小,優先分配記憶體位址比較大的位元組給變數 2.變數越先定義,記憶體位址就越大 5.乙個變數一定要進行初始化,才能使用 1.scanf函式中,要使用引數位址 引數名 例如 int number scanf d number 2.一次輸入多個...

C 教程02 C 環境

c 環境 在這一章中,我們將討論建立 c 程式設計所需的工具。我們已經提到 c 是 net 框架的一部分,且用於編寫 net 應用程式。因此,在討論執行 c 程式的可用工具之前,讓我們先了解一下 c 與 net 框架之間的關係。net 框架 net framework net 框架是乙個創新的平台,...