about “int const *p” and “const int *p ”

后端 未结 8 2001
無奈伤痛
無奈伤痛 2020-12-09 00:11
#include 
using namespace std;

int main(int argc, char* argv[])
{
    int i1 = 0;
    int i2 = 10;

    const int *p = &i1;
    int const *p2 =          


        
8条回答
  •  眼角桃花
    2020-12-09 00:36

    The two are exactly the same. What matters is the position of the qualifier relative to the asterisk (*):

    int const *p; // normal pointer to const int
    const int *p; // ditto
    
    int *const p; // const pointer to normal int (rarely useful)
    
    int const * const p; // const pointer to const int
    

提交回复
热议问题