• 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)
    
  • 相关阅读:
    NYOJ 10 skiing DFS+DP
    51nod 1270 数组的最大代价
    HDU 4635 Strongly connected
    HDU 4612 Warm up
    POJ 3177 Redundant Paths
    HDU 1629 迷宫城堡
    uva 796
    uva 315
    POJ 3180 The Cow Prom
    POJ 1236 Network of Schools
  • 原文地址:https://www.cnblogs.com/wyxy2005/p/2862405.html
Copyright © 2020-2023  润新知