久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

聲明類型的指針?

Declaring type of pointers?(聲明類型的指針?)
本文介紹了聲明類型的指針?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我剛剛讀到我們需要在 C(或 C++)中聲明指針時(shí)給出指針的類型,即:

I just read that we need to give the type of pointers while declaring them in C (or C++) i.e.:

int *point ;

據(jù)我所知,指針存儲(chǔ)變量的地址,無(wú)論類型如何,地址都占用相同數(shù)量的內(nèi)存.那么,為什么我們需要聲明它的類型?

As far as I know, pointers store the address of variables, and address occupies same amount of memory whatever may be the type. So, why do we need to declare its type?

推薦答案

類型安全.如果你不知道 p 應(yīng)該指向什么,那么就沒(méi)有什么可以防止像

Type-safety. If you don't know what p is supposed to point to, then there'd be nothing to prevent category errors like

*p = "Nonsense";
int i = *p;

靜態(tài)類型檢查是防止此類錯(cuò)誤的非常強(qiáng)大的工具.

Static type checking is a very powerful tool for preventing all kinds of errors like that.

C 和 C++ 還支持指針運(yùn)算,它僅在目標(biāo)類型的大小已知時(shí)才有效.

C and C++ also support pointer arithmetic, which only works if the size of the target type is known.

地址占用相同數(shù)量的內(nèi)存,無(wú)論我是什么類型

address occupies same amount of memory whatever my be the type

對(duì)于當(dāng)今流行的平臺(tái)來(lái)說(shuō)確實(shí)如此.但有些平臺(tái)并非如此.例如,指向多字節(jié)字的指針可能比指向單字節(jié)的指針小,因?yàn)樗恍枰硎咀衷谧謨?nèi)的偏移量.

That's true for today's popular platforms. But there have been platforms for which that wasn't the case. For example, a pointer to a multi-byte word could be smaller than a pointer to a single byte, since it doesn't need to represent the byte's offset within the word.

這篇關(guān)于聲明類型的指針?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡(jiǎn)單指針的區(qū)別?)
Difference between const. pointer and reference?(常量之間的區(qū)別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問(wèn)向量的內(nèi)容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對(duì)普通變量進(jìn)行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會(huì)導(dǎo)致訪問(wèn)沖突?)
主站蜘蛛池模板: a国产视频 | 欧美日在线 | 亚洲欧美综合精品久久成人 | 国产精品1 | 国产人久久人人人人爽 | 天堂在线免费视频 | 国产成人精品一区二区在线 | 欧美久久久久久久 | 久久久久九九九九 | 欧美亚洲综合久久 | 一级片在线播放 | 亚洲日本中文 | 亚洲午夜电影 | 欧美人人 | 日韩在线小视频 | 成人国产精品久久 | 91久久精品一区二区三区 | 五月香婷婷| 国产欧美日韩久久久 | 欧美精品一区二区三区四区 在线 | 国产激情偷乱视频一区二区三区 | 国产精品无码久久久久 | 成人在线视频免费看 | 青娱乐av | 蜜桃精品视频在线 | 午夜在线免费观看 | 国产日韩一区二区三免费 | 欧美1区| 中文字幕高清 | 久久综合狠狠综合久久综合88 | 亚洲欧美日韩久久久 | 精品免费国产一区二区三区四区介绍 | 日韩成人免费在线视频 | 精品久久久久久久久久久久久久久久久 | 成人亚洲| 99re99| 成人欧美一区二区三区黑人孕妇 | 国产黄色麻豆视频 | 成人不卡 | 国产精品视频一 | h片在线免费看 |