zoukankan      html  css  js  c++  java
  • 关于指针 用字符数组,字符指针变量输入字符串 动态为字符型指针变量分配内存

    #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");
    
    }

     指针数组呀

    #include <stdio.h>
    #include <iostream>
    #include<math.h>
    using namespace std;
    
    int main()
    {
             //声明指针数组
        char *colors[]={"Red","Blue","Yellow","Green"}; 
        //指向指针的指针变量
        char **pt;             
    
        //通过指向指针的变量访问其指向的内容
        pt=colors;
        for (int i=0;i<=3;i++) {
            cout<<"pt="<<pt<<endl;
            cout<<"*pt="<<*pt<<endl;
            cout<<"**pt="<<**pt<<endl;
            pt++;
        }
        system("pause");
    
    }
  • 相关阅读:
    phpstorm设置内存限制的方法
    PHP str_replace的用法
    php PDO getlastsql写法
    css3 transform做动画
    PHP判断是否关注微信公众号
    nginx目录安全设置
    BaseAdapter自定义适配器——思路详解
    sys.path
    plt.rcParams[]
    %matplotlib inline
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4565980.html
Copyright © 2011-2022 走看看