zoukankan      html  css  js  c++  java
  • c++ 数组及指针算术运算操作

    #include <iostream>
    #include <string>
    
        int main()  
        { 
            using namespace std;
            char t[5]={'a','b','c','f','g'};
           
            for(char *b=t,*q=b+5;b!=q;b++)
            {//注意cout对char类型的处理
                cout << (void*)b << endl;
           cout << b << endl;
           cout << *b << endl; } int t2[5]={1,2,3,4,5}; for(int *b=t2,*q=b+5;b!=q;b++) { cout << *b << endl; } int* t3=t2; cout << "&t2 pointer value = " << &t2 <<endl; cout << "t3 pointer value = " << t3 <<endl; cout << "*t2 value=" << *t2 <<" | " << "*t3 value = " << *t3<<endl; cout << "t2[0] value = " << t2[0] <<" | " << "t3[0] value = " << t3[0]<<endl; return 0; }

    注意上面代码,void*则为“无类型指针”void*可以指向任何类型的数据不能对void指针进行算法操作

     程序执行结果:

    a
    b
    c
    f
    g
    1
    2
    3
    4
    5
    &t2 pointer value = 0x22ac40
    t3 pointer value = 0x22ac40
    *t2 value=1 | *t3 value = 1
    t2[0] value = 1 | t3[0] value = 1
    
    运行 SUCCESSFUL (总时间:  110ms)
    
  • 相关阅读:
    MVC MVP MVVM
    RC4 对称加密
    ARM 寻址方式
    杂项记录 arm64 的一些特性
    无向图-笔记-代码
    iOS 自定义导航栏
    ios中设置UIButton圆角,添加边框
    iOS 中UICollectionView实现各种视觉效果
    UIScrollView中UITableView
    iOS 13 适配总结
  • 原文地址:https://www.cnblogs.com/wyxy2005/p/2862405.html
Copyright © 2011-2022 走看看