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

不支持在 c 或 c++ 中添加兩個指針.為什么?

Addition of two pointers in c or c++ not supported. why?(不支持在 c 或 c++ 中添加兩個指針.為什么?)
本文介紹了不支持在 c 或 c++ 中添加兩個指針.為什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

為什么 c 或 c++ 不支持添加兩個指針.

Why addition of two pointers not supported in c or c++.

當(dāng)我這樣做時,

int *ptr,*ptr1;
int sum = ptr + ptr1;

C 或 C++ 拋出錯誤.雖然它支持,

C or C++ throws an error. While it supports,

int diff = ptr - ptr1;

推薦答案

指針包含地址.添加兩個地址是沒有意義的,因為你不知道你會指向什么.減去兩個地址可以讓您計算這兩個地址之間的偏移量,這在某些情況下可能非常有用.

Pointers contain addresses. Adding two addresses makes no sense, because you have no idea what you would point to. Subtracting two addresses lets you compute the offset between these two addresses, which may be very useful in some situations.

為了解決尋找中頻的共同愿望,請考慮這一點(僅作為示例):

To address the common wish for finding the mid consider this (purely as an example):

#include <stdio.h>
int main (int argc, char **argv){
    int arr[] = {0,1,2,3,4,5,6,7,8,9};
    int *ptr_begin = arr;
    int *ptr_end = &arr[9];
    int *ptr_mid = ptr_begin + (ptr_end - ptr_begin)/2;
    printf("%d
", *ptr_mid);
}

我很確定你總能想出一個偏移計算,讓你用加法來實現(xiàn)你想要實現(xiàn)的目標(biāo).

I am quite sure that you can always come up with an offset-computation which lets do what you want to achieve with addition.

這篇關(guān)于不支持在 c 或 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?(為什么我不能對普通變量進行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導(dǎo)致訪問沖突?)
主站蜘蛛池模板: 色网在线看 | 成人av免费播放 | 特级毛片 | 国产91精品久久久久久久网曝门 | 一区二区三区视频 | 国产精品一区二区福利视频 | 免费黄色a级毛片 | 久久久免费毛片 | 午夜精品网站 | 国产91久久久久蜜臀青青天草二 | 不卡一区二区在线观看 | 天天爱av | 成人黄色电影免费 | 国产成人精品一区二区三区网站观看 | 黄色毛片在线播放 | 中文字幕日韩欧美一区二区三区 | 99热成人在线 | 国产精品观看 | 精品国产乱码久久久久久图片 | 亚洲天堂一区二区 | 国产内谢 | 韩日一区二区三区 | 久久国产日韩欧美 | 国产激情在线 | www久久爱 | 可以在线观看av的网站 | 国产午夜精品一区二区三区嫩草 | 久久99视频免费观看 | 婷婷在线免费 | 黄色片免费看 | 中国av在线免费观看 | 欧美日韩国产精品激情在线播放 | 黄色国产在线视频 | 国产在线一区观看 | 91精品国产综合久久久久久丝袜 | 91精品国产91久久综合桃花 | 国产黄色av网站 | 成人免费看黄网站在线观看 | 欧美一区永久视频免费观看 | 国产综合久久久久久鬼色 | 欧美日韩国产高清 |