const int i = 42;
auto j = i;
const auto &k = i;
auto *p = &i;
const auto j2 = i, &k2 = i;
?
i为const int型。
j为int型。
k为const int &型。
p为const int*型。
j2为const int型。
k2为const int &型。
/*************************************************************************
> File Name: ex2.35.cpp
> Author:
> Mail:
> Created Time: Mon 22 Jan 2024 03:02:48 PM CST
************************************************************************/
#include<iostream>
using namespace std;
int main(){
const int i = 42;
auto j = i;
j = 0;
cout<<"i = "<<i<<" j = "<<j<<endl;
const auto &k = i;
k = 0;
cout<<"k = "<<k<<endl;
auto *p = &i;
*p = 0;
cout<<"*p = "<<*p<<endl;
const auto j2 = i, &k2 = i;
j2 = 0;
k2 = 0;
cout<<"j2 = "<<j2<<" k2 = "<<k2<<endl;
return 0;
}