Dereferencing a pointer to constant

前端 未结 10 684
深忆病人
深忆病人 2020-12-30 23:09

Let\'s say we have a class called object.

int main(){
    object a;
    const object* b = &a;
    (*b); 
}

Question: b is a pointer to

10条回答
  •  长发绾君心
    2020-12-31 00:04

    const object* b = &a;
    

    b will treat what it points to as const, i.e. it cannot change a

    object* const b = &a;
    

    b itself is const, i.e. it cannot point to other object address, but it can change a

提交回复
热议问题