首页 > 编程语言 > 详细

关于指针 用字符数组,字符指针变量输入字符串 动态为字符型指针变量分配内存

时间:2015-06-10 15:27:44      阅读:253      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>
#include <iostream>
#include<math.h>
using namespace std;

int main()
{
     //声明字符型数组和指针变量
    char str[10];
    char *strip=str;

    //输入输出
    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");

}

 

关于指针 用字符数组,字符指针变量输入字符串 动态为字符型指针变量分配内存

原文:http://www.cnblogs.com/zhuyaguang/p/4565980.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!