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

是“一過即盡"嗎?非數(shù)組類型的指針是 C++ 中

Is the quot;one-past-the-endquot; pointer of a non-array type a valid concept in C++?(是“一過即盡嗎?非數(shù)組類型的指針是 C++ 中的有效概念嗎?)
本文介紹了是“一過即盡"嗎?非數(shù)組類型的指針是 C++ 中的有效概念嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

C++ 標(biāo)準(zhǔn) [sec 5.7] 說:

The C++ standard [sec 5.7] says:

如果指針操作數(shù)和結(jié)果都指向同一個數(shù)組對象的元素,或者一個過去數(shù)組對象的最后一個元素,求值不應(yīng)產(chǎn)生溢出;否則,行為是未定義.

If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined.

那么,我是否正確地假設(shè)數(shù)組以外的其他類型的指針未定義?

So, am I correct in assuming that pointers one-past-the-end of other types than arrays are undefined?

例如:

int a = 0;
vector<int> v(&a, (&a)+1);

上面的代碼片段編譯并運(yùn)行得很好(使用 g++),但它有效嗎?

The above snippet compiles and works just fine (with g++), but is it valid?

推薦答案

不,這是合法的.5.7(4) - 您引用前的一段 - 說:就這些運(yùn)算符而言,指向非數(shù)組對象的指針的行為與指向長度為 1 的數(shù)組的第一個元素,以對象的類型作為其元素類型."

No, it is legal. 5.7(4) - one paragraph before your quote - says: "For the purposes of these operators, a pointer to a nonarray object behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type."

這篇關(guān)于是“一過即盡"嗎?非數(shù)組類型的指針是 C++ 中的有效概念嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區(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++ - 如何從指向向量的指針訪問向量的內(nèi)容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進(jìn)行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導(dǎo)致訪問沖突?)
主站蜘蛛池模板: 99久久精品视频免费 | 精品不卡 | 一区二区三区四区在线视频 | 亚洲午夜视频在线观看 | 亚洲免费人成在线视频观看 | 91在线网| 久久成人一区 | 精品一区二区三区中文字幕 | 国产精品一区二区在线 | 欧美在线亚洲 | 国产精品久久久久久久久久 | 欧美午夜精品 | 在线播放第一页 | 一区二区精品 | 日本高清在线一区 | 久久精品影视 | 精品一区二区三区在线观看国产 | 免费一区 | 欧美视频三区 | 97精品久久 | 亚洲国产成人av好男人在线观看 | 国产精品国产a | 久草成人| 日日草天天干 | 日韩精品在线看 | 91小视频在线 | 亚洲一区二区中文字幕在线观看 | 国产精品国产精品国产专区不卡 | 精品视频一区二区三区 | 精品国产精品一区二区夜夜嗨 | 久久青| 国产免费看 | 999国产视频 | 久久国产欧美日韩精品 | 欧美一区二区免费 | 亚洲色图50p| 99热精品在线 | 亚洲精品一区二三区不卡 | 999精品在线观看 | 夜夜爽夜夜操 | 毛片免费在线观看 |