Dab tsi yog rvalue thiab lvalue hauv c ++?

Cov txheej txheem:

Dab tsi yog rvalue thiab lvalue hauv c ++?
Dab tsi yog rvalue thiab lvalue hauv c ++?

Video: Dab tsi yog rvalue thiab lvalue hauv c ++?

Video: Dab tsi yog rvalue thiab lvalue hauv c ++?
Video: What is the Difference Between a Pointer and a Reference C++ 2024, Hlis ntuj nqeg
Anonim

TL;DR: "lvalue" txhais tau tias "kev qhia uas tuaj yeem muab tso rau ntawm sab laug ntawm tus neeg ua haujlwm", lossis txhais tau tias "qhia uas muaj chaw nyob nco". " rvalue" txhais tau tias "tag nrho lwm cov kab lus ".

Lvalue thiab rvalue hauv C nrog piv txwv yog dab tsi?

Piv txwv li, Ib txoj haujlwm xav kom tus nqi raws li nws cov haujlwm sab laug, yog li cov hauv qab no siv tau: int i=10; Tab sis qhov no tsis yog: int i; 10=ib; Qhov no yog vim kuv muaj qhov chaw nyob hauv nco thiab yog lvalue. Thaum 10 tsis muaj qhov chaw nco tau txheeb xyuas thiab yog li ntawd yog rvalue.

Qhov txawv ntawm rvalue thiab lvalue yog dab tsi?

Ib qho lvalue yog hais txog ib yam khoom uas pheej mus dhau ib qho kev qhia. Ib qho rvalue yog tus nqi ib ntus uas tsis nyob dhau qhov kev qhia uas siv nws.

rvalue hauv C yog dab tsi?

L-tus nqi: "l-tus nqi" yog hais txog rau qhov chaw nco uas txheeb xyuas qhov khoom. l-tus nqi yuav tshwm sim li sab laug tes lossis sab xis ntawm tus neeg ua haujlwm ua haujlwm (=). l-tus nqi feem ntau sawv cev ua tus cim.

Dab tsi yog rvalue references?

Rvalue references yog ib qho kev txuas me me rau C ++ lus Rvalue references tso cai rau cov programmer kom tsis txhob muaj qhov tsis tsim nyog luam tawm thiab muab kev xa mus zoo tshaj plaws. Lawv feem ntau txhais tau tias pab tsim kev ua haujlwm siab dua thiab cov tsev qiv ntawv muaj zog dua.