zoukankan      html  css  js  c++  java
  • C++中一些容易迷惑的语法点总结

    #include<iostream>
    #include<cstring>
    using namespace std;
    int main(){
            int a[2][3]={{1,2,3},{4,5,6}};
            int *p=a[0];
            int (*pp)[3]=a;
            int *ppp[2]={a[0],a[1]};
            //the step is 3*4
            cout<<"a:"<<a<<endl;
            cout<<"a+1:"<<a+1<<endl;
            //the method to visit item
            cout<<"a[0][0]"<<a[0][0]<<endl;
    
            //the step is 4
            cout<<"a[0]:"<<a[0]<<endl;
            cout<<"a[0]+1:"<<a[0]+1<<endl;
            //the method to visit item
            cout<<"a[0][0]:"<<a[0][0]<<endl;
    
            //the step is 4
            cout<<"*p=a[0] p:"<<p<<endl;
            cout<<"p+1:"<<p+1<<endl;
            //the method to visit item
            cout<<"*(p+1):"<<*(p+1)<<endl;
    
            //the step is 3*4
            cout<<"(*pp)[3]=a pp:"<<pp<<endl;
            cout<<"pp+1:"<<pp+1<<endl;
            //the method to visit item
            cout<<"*(*(pp+1)+1)"<<*(*(pp+1)+1)<<endl;
    
            //the method to visit item
            cout<<"*(ppp[i]+j) or ppp[i][j]:"<<ppp[1][2]<<" or "<<*(ppp[1]+1)<<endl;
            return 0;
    }
    int getMemorySize(){
    cout<<"char:"<<sizeof(char)<<endl;
    cout<<"bool:"<<sizeof(bool)<<endl;
    cout<<"int:"<<sizeof(int)<<endl;
    cout<<"short int:"<<sizeof(short int)<<endl;
    cout<<"long int:"<<sizeof(long int)<<endl;
    cout<<"float:"<<sizeof(float)<<endl;
    cout<<"double:"<<sizeof(double)<<endl;
    cout<<"int*"<<sizeof(int*)<<endl;
    cout<<"double*"<<sizeof(double*)<<endl;
    return 0;
    }
    
    
    
     
     

     一、基本类型变量占用的内存问题

  • 相关阅读:
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业03
    C语言I博客作业02
    作业01
    java ui 点点记
    eclipse修改workspace目录
    postgres恢复
    JDK1.4和JDK1.5以及1.6
  • 原文地址:https://www.cnblogs.com/bobodeboke/p/3384615.html
Copyright © 2011-2022 走看看