const pointer & pointer const

#include “stdio.h”

int main(){
int x = 20;
int y = 30;
int *z = &x;
const int *a = &x; //const pointer
int * const b = &x; //pointer const
//*a = y; //错误
printf(“the addr of a = %p, *a = %d\n”, a,*a);
a = &y;
printf(“the addr of a = %p, *a = %d\n”, a,*a);
printf(“the addr of b = %p, *b = %d\n”, b,*b);
*z = 200;
//b = &y; //错误
printf(“the addr of b = %p, *b = %d\n”, b,*b);
printf(“the addr of x = %p, x = %d\n”, &x,x);
return 0;
}

the addr of a = 0x7ffc60f625a0, *a = 20
the addr of a = 0x7ffc60f625e0, *a = 30
the addr of b = 0x7ffc60f625a0, *b = 20
the addr of b = 0x7ffc60f625a0, *b = 200
the addr of x = 0x7ffc60f625a0, x = 200

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码运行时显示munmap_chunk(): invalid pointer,应该怎么修改?#include<iostream> #include<string> using namespace std; class Creature { public: Creature(const int& hands, const int& legs):_hands(hands),_legs(legs) {cout << "A Creature has been created!" << endl; cout << "It has " << hands << " hand(s)!" << endl; cout << "It has " << legs << " leg(s)!" << endl;} ~Creature() {cout << "Creature object exiled!" << endl;} int GetHands() const {return _hands;} int GetLegs() const {return _legs;} private: int _hands; int _legs; }; class Beast:virtual public Creature { public: Beast(const int& hands, const int& legs, const string& name) :Creature(hands,legs),_name(name){cout << "Its beast name is " << _name << endl;} ~Beast() {cout << "Beast object exiled!" << endl;} string GetName() const {return _name;} private: string _name; }; class Human:virtual public Creature { public: Human(const int& hands, const int& legs, const string& name):Creature(hands,legs),_name(name) {cout << "Its human name is " << _name << endl;} ~Human() {cout << "Human object exiled!" << endl;} string GetName() const {return _name;} private: string _name; }; class Orc:public Human,public Beast { public: Orc(const int& hands, const int& legs, const string& beast_name, const string& human_name):Creature(hands, legs),Beast(hands,legs,beast_name),Human(hands,legs,human_name){} ~Orc() {cout << "Orc object exiled!" << endl;} string GetBeastName() const {return Beast::GetName();} string GetHumanName() const {return Human::GetName();} };
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值