ch8_17.cpp
Upload User: gzy2011
Upload Date: 2021-02-09
Package Size: 20k
Code Size: 0k
Development Platform:

Visual C++

  1. //file ch8_17.cpp
  2. #include"iostream.h"
  3. void main(void)
  4. {
  5.  char buffer[10]="ABC";
  6.  char* pc;
  7.  pc="hello";
  8.  cout<<pc<<endl; //输出字符指针就是输出字符串:"hello",而非地址,除非如下:
  9.  cout<<hex<<(int)pc<<endl;//输出地址
  10.  pc++;           //pc指向'e'
  11.  cout<<pc<<endl;  //"ello"
  12.  cout<<*pc<<endl; //'e'
  13.  
  14.  pc=buffer; //pc指向"ABC"
  15.  cout<<pc<<endl; //"ABC"
  16. }