// p45.cpp : Defines the entry point for the console application.//
#include "stdafx.h"using namespace std;
int _tmain(int argc, _TCHAR* argv[]){ //声明字符型数组和指针变量 char str[10]; //char *strip=str; //等价 char *strip; strip = &str[0];
//输入输出 cout<<"str="; cin>>str; //用字符数组输入字符串 cout<<"str="<<str<<endl; cout<<"strip="<<strip<<endl; cout<<"strip="; cin>>strip; //用字符指针变量输入字符串 cout<<"str="<<str<<endl; cout<<"strip="<<strip<<endl; //利用指针变量改变其指向字符串的内容 *(strip+2)='l'; cout<<"str="<<str<<endl; cout<<"strip="<<strip<<endl;
//动态为字符型指针变量分配内存 strip=new char(100); cout<<"strip="; cin>>strip; //用字符指针变量输入字符串 cout<<"str="<<str<<endl; cout<<"strip="<<strip<<endl;
system("pause"); return 0;}