pointerassignment.cpp

来自「ThinkingC++中文版」· C++ 代码 · 共 31 行

CPP
31
字号
//: C08:PointerAssignment.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
#include <iostream>
using namespace std;



void main()
{
   
	int d = 1;	
	int* u  ;
	const int e = 2;   //常量对象
	const int *pointer_const;	 //常量指针


	pointer_const = &d;	 //	 assign the address of a non-const object to a const pointer 
	pointer_const = &e;
	u = &d; // OK -- d not const
	//!u = &e;	   // Illegal -- e const


	int* w = (int*)&e; // Legal but bad practice
 	*w=4;	  //设置断点,发现e值已改变!
	cout<<"e="<<e<<endl;

} ///:~

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?